List of all fields in respective tables - list

I was trying to get a list of all the fields in all the tables in Access 2007. I tried a bunch of macro suggestions I found, but none of them worked, does anyone have an idea?

You could make a DAO-Connection to CurrentDb and Loop through the TableDefs-Object to get all tables. The use the Fields-Collection.

Related

How does distinct parameter work with the Count method in annotate?

I got a problem with annotate method when I was using the Count method to count multiple columns that come from the database which have a relationship with one of the tables.
Let me give you a quick example:
match_session_instance = MatchSessionInstance.objects.filter(match_session=match_session, status="main")
match_instances = MatchSessionInstance.objects.filter(match_session=match_session)
action_counts = match_instances.values(player_number=F("player_pk__number"), player_name=F("player_pk__player"))\
.annotate(pass_count=Count("live_match_pass__id", distinct=True),
corner_count=Count("live_match_corner__id", distinct=True))
In the meantime, I'm not facing any problems - I caught my issue and I addressed it but that is the problem now.
I don't know how could "disticnt=True" parameter helps me to fix that problem!
I googled a bit and found this source that has helped me:
Count on multiple fields in Django querysets
I know what does distinct as a method in ORM but actually, I get no idea how it works in that format special when I used columns that never have duplicated data.
How can I understand this?

Updating 10,000 records - what is the best way

I need to update 10,000 records and am wondering what is the quickest way, this is what I am doing currently
I get all the records I need to update, a big list of sku's. I then loop through that list and update them. In the below
in_both is my list of skus
I loop through, get the reference in ShopReconciliation and update
for line_item, sku enumerate(in_both):
got_products = ShopReconciliation.objects.filter(sku=sku, run_id=self.reconciliation_id)
for got_product in got_products:
got_product.in_es = True
got_product.save()
This works, but strike me it isn't very quick. I could have 60k records
Is there a better way with so many records
Thanks
cursor.executemany is supported by most libraries like cx_Oracle or pyodbc. May check the database and data access library for availability of the function.
In the end I used transaction.atomic (with the With)
That seemed to work, I just need to be careful if an error occurs before the commit

Best practice for using Django templates and connect it to database

I am trying to build a database for my website. There are currently three entries with different attributes in my database. I have not created these entries in order, but I have assigned a 'Chapter number' attribute which indicates the order 1,2,3.
I am now trying to inject this using 'context' and 'render' function in my views. I am using the method 'objects.all()' to add all objects to my context. I have a simple Html file where I am inserting the data from the database by looping over (a simple for loop) these added objects.
Now the output that is being generated (naturally) is that it is following the order in which I created the database. I am not sure how I can have the loop run in such a way that I get these chapters in correct order. Thank you for patiently reading my question. Any help will be appreciated.
You may use the order_by method which is included in Djangos QuerySet API:
https://docs.djangoproject.com/en/3.0/ref/models/querysets/
If you offer some more information of your specific data I might provide you with an example.
For orientation purposes, sorting queried objects by date would work as follows:
most_recent = Entry.objects.order_by('-timestamp')
You can sort by any field like so:
sorted_by_field = Entry.objects.order_by('custom_field')

trouble using distinct() and filter() in django with an Oracle backend

I'm trying to get a list of all the distinct values field B can take given a value for field A. I'm using django 1.10 and Oracle 12g.
I tried MyModel.objects.filter(fieldA='foo').values_list('fieldB').distinct() but this gives me a list with many duplicates, as if distinct() simply isn't working. I can get rid of the duplicates by converting the list to a set in python, but I'd like to rely on the database.
thanks for any help you can give
You should use order_by in conjunction with distinct to get distinct values
MyModel.objects.filter(fieldA='foo').order_by('fieldB').values_list('fieldB', flat=True).distinct()

Updating two tables, retrieving Foreign Key

I am inserting data into two tables, however I can not figure out (after hours of Googling) how to insert data into the second table after retrieving the new ID created after the first update?
I'm using <CFINSERT>.
use <CFQUERY result="result_name"> and the new ID will be available at result_name.generatedkey .. <cfinsert> and <cfupdate>, while easy and fast for simple jobs, they are pretty limited.
I have never used cfinsert myself, but this blog post from Ben Forta says you may not be able to use cfinsert if you need a generated key http://www.forta.com/blog/index.cfm/2006/10/3/Use-CFINSERT-And-CFUPDATE
Yes, I realize that blog post is old, but it doesn't appear much has changed.
Why not use a traditional INSERT statement wrapped in a <cfquery> tag?