I don't know what the error means, but this looks like the sort of thing you might want to put on a custom Manager instead -- then you could say `Settore.objects.get_default()`.
http://docs.djangoproject.com/en/dev/topics/db/managers/#topics-db-managers (I have a feeling the error wouldn't happen if it was on a manager class.) On Mon, Oct 26, 2009 at 12:22 PM, Alessandro Ronchi <alessandro.ron...@soasi.com> wrote: > > I need to create a static method for a model class like this. The line > Settore.objects.all()[0].id gives error ( > psycopg2.InternalError: current transaction is aborted) when creating > the tables at first syncdb. What's the correct way to do that? > > ~~~~~~~~~~~~~~~~~~~~~~~~~ > class Settore(models.Model): > nome = models.CharField(max_length=200, blank=False, null=False) > email = models.EmailField() > > class Meta: > > verbose_name_plural = 'settori' > ordering = ('nome',) > get_latest_by = "nome" > > def __unicode__(self): > return self.nome > > �...@staticmethod > def get_default(): > try: > return Settore.objects.all()[0].id > except: > return None > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > -- > Alessandro Ronchi > > SOASI > Sviluppo Software e Sistemi Open Source > http://www.soasi.com > http://www.linkedin.com/in/ronchialessandro > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---