tblEntryObj seems to be an instance of your model, it is not a dictionary,
so normally it wouldn't have a "keys" method.

On Wed, Apr 15, 2015 at 5:32 PM, Henry Versemann <fencer1...@gmail.com>
wrote:

> Vijay,
>
> I tried your method, and while it got me the table class that I wanted,
> for some reason when I try to get into the actual list of entries in the
> desired table, I can't seem to get to either the keys or values of any of
> the list objects.
> So I'm not sure what's going on.
> Here's some condensed code of what I've done so far:
>
>             for entry in tblsLst:
>                 entryKeys = entry.keys()
>                 table_name = str(entryKeys[0])
>                 table_class = get_model('canvas_app',table_name)
>                 tblEntryLst = table_class.objects.all()
>                 lstLgth = len(tblEntryLst)
>                 for loopindx in range(lstLgth):
>                     tblEntryObj = tblEntryLst[loopindx]
>                     tblEntryObjKeys = tblEntryObj.keys()
>
> And I seem to be getting an AttributeError exception on the last line
> above.
> When I print the size or contents (table objects format (the objects are
> listed like this:
>
>     <CanvasRequests: CanvasRequests object>
>
> ) no internal value to see) of the tblEntryLst everything looks right.
> Is there anything you can suggest for determining where the problem might
> be?
>
> Thanks for the help.
>
> Henry
>
>
> On Wednesday, April 15, 2015 at 12:43:28 PM UTC-5, Vijay Khemlani wrote:
>
>> You can use get_model
>>
>> from django.db.models.loading import get_model
>>
>> YourModel = get_model('your_app', tableName)
>>
>> On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase <django...@tim.thechases.com>
>> wrote:
>>
>>> On 2015-04-15 09:45, Henry Versemann wrote:
>>> > My problem is since the logic won't know which tables will be in
>>> > the incoming list I need to try to reference the entries in each
>>> > table using some kind of evaluated version of a variable containing
>>> > the name of each table, as I iterate through the list.
>>> >
>>> > I'm sure I could do this using an "eval" statement like this
>>> >
>>> > tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
>>> >
>>> > eval(tblComannd)
>>>
>>> Since it's just Python, you can create mappings of the table-objects,
>>> and then get attributes on them.
>>>
>>>   table_names = {
>>>     "tblA": tblA,
>>>     "tblB": tblB,
>>>     "tblRenamed": tblXYZ,
>>>     }
>>>
>>>   for name, cls in table_names.items():
>>>     log.info("Dumping %s", name)
>>>     for item in cls.objects.all():
>>>       write_to_file(item)
>>>
>>> Presumably, these classes come from some namespace like a module, so
>>> you can even do something like
>>>
>>>   import models
>>>   table_names = ["tblA", "tblB"]
>>>   for name in table_names:
>>>     log.info("Dumping %s", name)
>>>     cls = getattr(models, name)
>>>     for item in cls.objects.all():
>>>       write_to_file(item)
>>>
>>> -tim
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/20150415120110.77c4ea6f%40bigbox.christie.dr.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3d659059-6219-4266-93f9-4e56dc348e49%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3d659059-6219-4266-93f9-4e56dc348e49%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1mbXGN3PNWpnqg0Cjg-rvOP738U5dqDEAY_0%2B%3DAy-Zpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to