Hi
I have few models in a app called shoppingcart.
I can find contenttypes associated with this model with this:
>>>ct = ContentType.objects.filter(app_label='shoppingcart')
>>>ct
[<ContentType: cart>, <ContentType: cart item>, <ContentType: cart rule>,
<ContentType: condition set>]
but when i try ct[0].model_class() it returns the model class on shell but
gives me a NoneType when i try to get all models as a tuple so that i can
populate them as choices of field with this iterator MODELCHOICES = [each
for each in GetAllModels]
I have the required tables in database. (had once deleted all contenttypes
for this app and synced db to recreate the table)
class GetAllModels(object):
def __init__(self,counter=0):
self.counter = counter
def __iter__(self):
return self
def next(self):
ct =
list(ContentType.objects.filter(app_label__in=['shoppingcart','products','productoptions']))
if self.counter < len(ct):
mclass = ct[self.counter].model_class()
self.counter = self.counter +1
return ('.'.join([mclass.__module__,mclass.__name__]),
mclass.__name__)
else:
raise StopIteration
Please enlighten me !
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.