Still hoping someone has some insight here.  I've been plugging away
at it and am still not finding an answer I can live with as an
engineer.

Currently I'm cheating a bit to filter down by only published objects
in my view like so

    tag = get_object_or_404(Tag, slug=slug)

    contentitems = tag.taggeditem_set.all()

    contentlist = [item for item in contentitems if
item.content_object.status == 'P']

Obviously this seems a bit sloppy and I'm probably better off putting
this in a custom related manager that catches errors if I'm trying to
filter on fields that a model doesn't have (which could happen in
generic models).

It doesn't do well at ordering obviously.

I'm still struggling with this though and am not sure generic tagging
is the way I should be going with this.  Still appreciate any insight
out there.


On May 24, 10:05 am, Streamweaver <streamwea...@gmail.com> wrote:
> I'm trying to implement tagging using Content Types and Generic
> Relationships.    What I want to is query any tagged item with a
> status of Published.
>
> All my tagged models are implementing an Abstract Model class with a
> status field so they share the 'Published' and 'Unpublished' types.
>
> Here are some cut down version of the models I'm using for an
> example.    Right now I only have Posts related to Tags but I plan on
> adding flat pages and such.  What I want to be able to have pages for
> tags return all content with a status of Published but I don't seem to
> be able to find a way to do this.  I can find content and tags just
> fine but when I have to filter it further I'm stumbling and would
> appreciate any insight or pointers to example code.  I've seen some
> examples of custom managers online but the folks there are writing
> naked SQL in the managers and I'd like to avoid going that route if I
> can
>
> class Tag(models.Model):
>
>     text = models.CharField(max_length=30, unique=True)
>     slug = models.SlugField(max_length=30, unique=True, null=True,
> blank=True)
>
> class TaggedItem(models.Model):
>
>     tag = models.ForeignKey(Tag)
>
>     content_type = models.ForeignKey(ContentType)
>     object_id = models.PositiveIntegerField()
>     content_object = generic.GenericForeignKey('content_type',
> 'object_id')
>
> class Post(models.Model):
>
>     title = models.CharField(max_length=75)
>     ...
>     status = models.CharField(max_length=1, choices=POST_STATUS)
>
>     topics = generic.GenericRelation(TopicCatalog)
>     tags = generic.GenericRelation(TagCatalog)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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