- Author:
- vijay.shanker
- Posted:
- February 11, 2013
- Language:
- Python
- Version:
- 1.4
- Score:
- -1 (after 1 ratings)
all_models = [ each for each in GetAllModels() ]
This produces a list of tuples in format ( app_label's name, model's name) of all the ContentType existing in system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from django.contrib.contenttypes.models import ContentType
class GetAllModels(object):
''' an iterator function to produce model names installed as choices format '''
def __init__(self,counter=0):
self.counter = counter
def __iter__(self):
return self
def next(self):
ct = ContentType.objects.all()
if self.counter < len(ct)-1 :
self.counter = self.counter +1
return (ct[self.counter].app_label, ct[self.counter].model)
else:
raise StopIteration
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Use the Power, Luke!
#
Please login first before commenting.