How are you deciding which post is pinned?
The unique approach might not do any good to you.
A simple solution is to update the pinned values of each post to False & 
setting the required post pinned value to True when you are setting a 
pinned post.
There may be better solutions, but I hope this might help you.


On Friday, October 5, 2018 at 10:06:48 PM UTC+5:30, Chuka Nwadiogbu wrote:
>
> Hi, I know it has been a while since this question was asked but I have  a 
>> similar question. I have a Post model, and I want there to be one pinned 
>> post out of the list of all posts, I tried creating a new property thus, 
>
>    
> ```pinned = models.BooleanField(default=False, unique=True)```
>
> but it caused major problems. I want to have just one pinned post and the 
> rest unpinned but that would mean pinned = True for one post/article and 
> pinned=False for the rest and I don't think that is how unique is supposed 
> to work. Unique is supposed to be different for all the objects right? not 
> sure how to tackle this problem.
>
> someone suggested I use a foreignkey field to link them all together but 
> now if I'm being honest, I actually do not know where to go from here 
>
> ```class PinnedPost(models.Model):
> pinned_post = models.ForeignKey(Post, related_name='pinned', 
> on_delete=models.CASCADE)``` 
> if there's anyone here that can help me with this please, I'd really 
> appreciate it. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ba74428-19b6-4d60-9445-e6ace97297e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to