I'm using the object_list generic view to quickly list a set of Articles. Each Article has comments attached to it. The query uses an annotation to Count() the number of comments and then order_by() that annotated number.
'queryset': Article.objects.annotate(comment_count=Count('comments')).order_by('-comment_count'),
The comments a...
Say I have the following models:
class Image(models.Model):
image = models.ImageField(max_length=200, upload_to=file_home)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
class Article(models.Model):
text = models.TextField()
...
heya,
I have a Django project, that has a "Address" model. This is used in several places - by a "User Profile" model, by a "Hospital" model, by an "Insitution" model etc.
I'm using Django's generic relations to allow each of these objects to create a foreign-key to Address.
However, this seems to cause some weirdness in the Django Ad...
Hi!
i'm developing a authentication backend with object-based permissions for my django-app.I use generic relations between an object and a permission:
class GroupPermission(models.Model):
content_t= models.ForeignKey(ContentType,related_name='g_content_t')
object_id = models.PositiveIntegerField()
content_object = generic.G...
I ran the code to create the generically related objects from this demo:
http://www.djangoproject.com/documentation/models/generic_relations/
Everything is good intially:
>>> bacon.tags.create(tag="fatty")
<TaggedItem: fatty>
>>> tag, newtag = bacon.tags.get_or_create(tag="fatty")
>>> tag
<TaggedItem: fatty>
>>> newtag
False
But then...