Or more specifically, why exactly do you want to reorder them all at every Subject .save()? And what exactly do you use the values in 'order' field for?
On Mar 10, 11:46 pm, Beres Botond <boton...@gmail.com> wrote: > Even if we ignore the infinite loop, selecting and updating every > single instance of Subject at every save() of a Subject, is horribly > wrong and inefficient on many levels. > > Exactly what kind of functionality/logic were you trying to implement? > > On Mar 10, 10:32 pm, Ali Rıza Keleş <ali.r.ke...@gmail.com> wrote: > > > Hi all, > > > I want to override saving of one of my models. > > After saving any record, I am trying to reorder them all. > > > class Subject(models.Model): > > slug = models.SlugField(db_index=True, unique=True) > > name = models.CharField(max_length="120") > > order = models.CharField(blank = True, max_length="3") > > > class Meta: > > ordering = ['order'] > > > def __unicode__(self): > > return u'%s' % (self.name) > > > def __str__(self): > > return self.__unicode__() > > > def save(self, *args, **kwargs): > > super(Subject, self).save(*args, **kwargs) > > self.makeOrder() > > > def makeOrder(self): > > t = 10 > > for i in Subject.objects.all().order_by('order'): > > i.order = t > > i.save() > > t += 10 > > > But here, It fails in a loop and give "maximum recursion depth exceeded" > > error. > > > How can I do? > > > Thanks.. > > > -- > > Ali -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.