mirror of
https://github.com/jazzband/django-categories.git
synced 2026-05-16 19:41:08 +00:00
Added some docs and testing apps
This commit is contained in:
parent
b0468cc8e4
commit
81d07c859d
3 changed files with 32 additions and 6 deletions
|
|
@ -17,8 +17,25 @@ categories.register_m2m(MyModel)
|
|||
|
||||
If you want more than one field on a model you have to have some extra arguments
|
||||
|
||||
import categories
|
||||
categories.register_fk(MyModel, 'primary_category')
|
||||
categories.register_fk(MyModel, 'secondary_category', {'related_name':'mymodel_sec_set'})
|
||||
import categories
|
||||
categories.register_fk(MyModel, 'primary_category')
|
||||
categories.register_fk(MyModel, 'secondary_category', {'related_name':'mymodel_sec_set'})
|
||||
|
||||
The ``extra_args`` allows you to specify the related_name of one of the fields so it doesn't clash.
|
||||
The ``extra_args`` allows you to specify the related_name of one of the fields so it doesn't clash.
|
||||
|
||||
|
||||
Extra fields with Many-to-Many Categories
|
||||
=========================================
|
||||
|
||||
Occasionally you may want to add one or more fields to the categories you relate to a given model. For example, you may want an easy way to select one of the categories to be "primary." This requires a bit more work.
|
||||
|
||||
1. Create the intermediary class::
|
||||
|
||||
from categories.models import CategoryIntermediary
|
||||
|
||||
# We're assuming that there is a ``Blog`` model previously defined
|
||||
# or imported
|
||||
class BlogCategories(CategoryIntermediary):
|
||||
blog = models.ForeignKey(Blog)
|
||||
|
||||
categories.register_m2m(Blog, extra_args={'through':'BlogCategories'})
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
from models import SimpleText
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.register(SimpleText)
|
||||
|
||||
class SimpleTextAdmin(admin.ModelAdmin):
|
||||
filter_horizontal = ['cats',]
|
||||
|
||||
|
||||
admin.site.register(SimpleText, SimpleTextAdmin)
|
||||
|
|
@ -27,5 +27,9 @@ class SimpleText(models.Model):
|
|||
return ('simpletext_detail_view_name', [str(self.id)])
|
||||
|
||||
import categories
|
||||
from categories.models import CategoryIntermediary
|
||||
class SimpleTextCategories(CategoryIntermediary):
|
||||
simpletext = models.ForeignKey(SimpleText)
|
||||
|
||||
categories.register_fk(SimpleText, 'primary_category', {'related_name':'simpletext_primary_set'})
|
||||
categories.register_m2m(SimpleText, 'cats')
|
||||
categories.register_m2m(SimpleText, 'cats', )
|
||||
Loading…
Reference in a new issue