list of all app_label, model of existing contentTypes

 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

  1. ContentType Form by nosrednakram 3 years, 8 months ago
  2. RFC: Shim to allow view classes rather than functions by peterbraden 4 years, 2 months ago
  3. Comma Seprated Character Field to store Geographic Coordinates by vijay.shanker 5 months ago
  4. Application Name DatabaseRouter by kraiz 7 months, 2 weeks ago
  5. db_dump.py - for dumpping and loading data from database by limodou 6 years, 2 months ago

Comments

doomatel (on February 12, 2013):

Use the Power, Luke!

ContentType.objects.values_list('app_label', 'model')

#

(Forgotten your password?)