3
I extended the class django.db.models.Manager
to pick up the records that are públicos
and by doing so I can no longer list all the calling records Product.objects.all()
Even in my administration area, only public status records are listed. Private status records are hidden.
my mobile is
STATUS_PUBLISH = (
('público', 'pùblico'),
('privado', 'Privado'),
)
class ProductManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(status_publish='público')
class Product(TimeStampedModel):
name = models.CharField(max_length=255, blank=False, null=False, unique=True)
slug = models.SlugField(max_length=255, blank=False, null=False)
description = models.TextField(blank=True, null=True)
status_publish = models.CharField(max_length=10, choices=STATUS_PUBLISH, default='público')
tags = TaggableManager(blank=True, help_text='Separe as categorias com vírgula')
publish = ProductManager()
objects = models.Manager()
class Meta:
ordering = ('name',)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("gallery:product_update", kwargs={"slug": self.slug})
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
return super(Product, self).save(*args, **kwargs)
"Even in my area of admin only appear the registration with 'public status`". This statement you say that even saving the private option, the record changes to the public, or only those that are saved as public are presented q?
– Carlos Cortez
This, only those that are saved as 'public' are displayed. Those that are 'private' do not appear.
– danilomarto