Re: How to Create an Auto Incrementing Integer Field
Thank you very much, that was exactly what I was looking for.
On Monday, 22 July 2013 09:48:51 UTC-4, Christian Erhardt wrote:
--Have a look at this post: http://stackoverflow.com/questions/3123796/how-to- make-an-auto-filled-and-auto- incrementing-field-in-django- admin They determine the next value by calling a function called number(). In your case it would look something like this:class Cliente(models.Model):"""This is the client data model, it holds all client information. Thisdocstring has to be improved."""def number():no = Cliente.objects.all().aggregate(Max(order)) if no == None:return 1else:return no + 1clientcode = models.IntegerField(_('Code'), max_length=6, unique=True, \default=number)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home