aaronvanderlip avatar aaronvanderlip committed fad5f7c

Renamed instance_manager to manager to keep with Django conventions

Comments (0)

Files changed (2)


             objects = models.Manager()
             title = models.CharField(max_length=200)
-            slug = AutoSlugField(populate_from='title', unique_with='pub_date__month', instance_manager=objects)
+            slug = AutoSlugField(populate_from='title', unique_with='pub_date__month', manager=objects)
         class NewsArticle(Article):
         # When using model inheritence, set manager to search for matching
         # slug values
-        self.instance_manager = kwargs.pop('instance_manager', None)
+        self.manager = kwargs.pop('manager', None)
         self.always_update = kwargs.pop('always_update', False)
         super(SlugField, self).__init__(*args, **kwargs)
         # get currently entered slug
         value = self.value_from_object(instance)
-        instance_manager = self.instance_manager
+        manager = self.manager
         # autopopulate
         if self.always_update or (self.populate_from and not value):
         # ensure the slug is unique (if required)
         if self.unique or self.unique_with:
-            slug = utils.generate_unique_slug(self, instance, slug, instance_manager)
+            slug = utils.generate_unique_slug(self, instance, slug, manager)
         assert slug, 'value is filled before saving'


         attr = getattr(instance, field.populate_from)
         return callable(attr) and attr() or attr
-def generate_unique_slug(field, instance, slug, instance_manager):
+def generate_unique_slug(field, instance, slug, manager):
     Generates unique slug by adding a number to given value until no model
     instance can be found with such slug. If ``unique_with`` (a tuple of field
     index = 1
-    if not instance_manager:
-        instance_manager = type(instance).objects
+    if not manager:
+        manager = type(instance).objects
     # keep changing the slug until it is unique
     while True:
         # find instances with same slug
         lookups = dict(default_lookups, **{field.name: slug})
-        rivals = instance_manager.filter(**lookups).exclude(pk=instance.pk)
+        rivals = manager.filter(**lookups).exclude(pk=instance.pk)
         if not rivals:
             # the slug is unique, no model uses it
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.