from django.db import models
class Product(models.Model):
title = models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
class ProductImage(models.Model):
product = models.ForeignKey(Product)
image = models.ImageField(upload_to='products/images/')
is_default_image = models.BooleanField(default=False,null=False,blank=False)
class Meta:
# A product can have multiple ProductImages, but only one of them can be the "default"-image
unique_together = ('product', 'is_default_image')
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)```
--
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...@googlegroups.com.
To post to this group, send email to django...@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/31bc4205-e1fd-4e59-aa47-a488884253eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.