On Jun 5, 6:56 pm, "eric.frederich" <eric.freder...@gmail.com> wrote:
> How can I get distinct content_types from a model like this?...
>
> In sqlite I did the following and it worked...
> sqlite> select distinct content_type_id from booking_managedasset;
>
> class ManagedAsset(models.Model):
>     content_type   = models.ForeignKey(ContentType)
>     object_id      = models.PositiveIntegerField()
>     content_object = generic.GenericForeignKey('content_type',
> 'object_id')
>     name   = models.CharField(max_length=100, unique=True,
>              help_text='Asset Name')
>     slug   = models.SlugField(max_length=100, unique=True,
>              help_text='Slug')
>
> This works in Django but it is getting all objects from the database
> and then using Python to make them distinct.
> set([ma.content_type for ma in ManagedAsset.objects.all()])
>
> Is there a way to accomplish this using Django queries?

ManagedAsset.objects.values_list('content_type', flat=True).distinct()
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to