ok the First option i dropped the postgres database and made a new one, so no chance of duplicate data there
now the second part i am confused now how can there be duplicates ? i do have a manytomany field maybe because of that ?
here are all of my models
# Create your models here.
def file_directory_path(instance, filename):
return f"{instance.country}/{instance.shop}/{filename}"
class retailer(models.Model):
links = models.CharField(max_length=9999, unique=True)
shop = models.CharField(max_length=100)
country = models.CharField(max_length=300)
category = models.CharField(max_length=300)
title = models.CharField(max_length=300)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = ResizedImageField(
size=[250, 250], quality=100, upload_to=file_directory_path)
color = models.CharField(max_length=300)
slug = AutoSlugField(
populate_from=['country', 'shop', 'category', 'title'])
date_posted = models.DateTimeField(default=timezone.now)
no_of_likes = models.IntegerField(
default=0, validators=[MinValueValidator(0)])
liked_by = models.ManyToManyField(User, related_name='likes', blank=True)
def __str__(self):
return self.title
def save(self, *args, **kwargs):
self.shop = self.shop.strip()
super().save(*args, **kwargs)
def count(self):
return self.count()
class Like(models.Model):
retailer = models.ForeignKey(retailer, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
date_liked = models.DateTimeField(default=None, null=True, blank=True)
# class Meta:
# unique_together = ['retailer', 'user']
def __str__(self):
return str(self.retailer) + " - " + str(self.user) + " - " + str(self.date_liked)
class unique_colors(models.Model):
color_name = models.CharField(max_length=300, unique=True)
color_image = models.FileField(upload_to="color_images")
def __str__(self):
return self.color_name
# Profile Models Started Below
class main_profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_img = ResizedImageField(
size=[250, 250], quality=100, upload_to='profile_img', default='default_profile.jpg', blank=True)
bio = models.TextField(blank=True)
location = models.CharField(max_length=30, blank=True)
no_of_followers = models.IntegerField(
default=0, validators=[MinValueValidator(0)])
followed_by = models.ManyToManyField(
User, related_name='followers', blank=True)
no_of_following = models.IntegerField(
default=0, validators=[MinValueValidator(0)])
following = models.ManyToManyField(
User, related_name='following', blank=True)
affiliate_id = models.CharField(max_length=100, default=uuid.uuid4,unique = True, blank= True, null = True)
def __str__(self):
return self.user.username
class Notification(models.Model):
send_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='sender')
received_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='receiver')
message = models.CharField(max_length=255)
read = models.BooleanField(default=False)
created_at = models.DateTimeField(default=None, null=True, blank=True)
def __str__(self):
return self.message