These are chat archives for django/django

4th
Aug 2016
Roel
@roelzkie15
Aug 04 2016 04:04
hello there i am new to django, i would like to ask a question how to set a model relationship constraint to on_update = models.CASCADE because i cant find any example in the documentation except on_delete = models.CASCADE
Antonio Carlos L. Ortiz
@antoniocarlosortiz
Aug 04 2016 11:37
@badcoder28 what are you trying to do?
Shakib Hossain
@shakib609
Aug 04 2016 12:03
I have a Like model.
There are 2 columns post and liked_by.
How can I make a row of that table unique with Django ORM? Any advise?
Yoong Kang Lim
@yoongkang
Aug 04 2016 14:14
@shakib609: what about unique_together?
phanhoang17
@huyhoang17
Aug 04 2016 16:23
Hey, I'm trying to create a website eCommerce using Django. Can anyone suggest what I can do now?
Vlad Fernandes
@Vlad-Fernandes
Aug 04 2016 17:14
@huyhoang17 is it a personal site?
Shakib Hossain
@shakib609
Aug 04 2016 18:05
@yoongkang Yeah. It worked. Didn't know about that option before. Thanks. :+1:
Oclay
@Oclay2_twitter
Aug 04 2016 18:41
@antoniocarlosortiz Why django don't have native on_delete and on_update for databases?
Fábio C. Barrionuevo da Luz
@luzfcb
Aug 04 2016 19:04

hello Django-users,

it is possible to include a select_related by default when I use an Custom Queryset as Manager?

basically I want to turn this code:

class SignatureQuerySet(models.QuerySet):
    def active(self):
        return self.filter(active=True)

    def inactive(self):
        return self.filter(active=False)


class SignatureManager(models.Manager):
    queryset_class = SignatureQuerySet

    def get_queryset(self):
        return self.queryset_class(model=self.model, using=self._db).select_related('document')

    def active(self):
        return self.get_queryset().filter(active=True)

    def inactive(self):
        self.get_queryset().filter(active=False)

class Signature(models.Model):
    document = models.ForeignKey('Document', related_name='documents_signatures')

    manager = SignatureManager()

into this



class SignatureQuerySet(models.QuerySet):
    # declare somehow select_related('document') as the default queryset

    def active(self):
        return self.filter(active=True)

    def inactive(self):
        return self.filter(active=False)


class Signature(models.Model):
    document = models.ForeignKey('Document', related_name='documents_signatures')

    manager = SignatureQuerySet.as_manager()