I'm new to django, but coming from php I think its the greatest thing ever.
I have a model for Invoices ...
{{{
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
#from django.contrib.auth.models import User
# Create your models here.
class Invoice(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
their_company = models.CharField(max_length=255)
invoice_number = models.CharField(max_length=50, default='')
bill_to = models.CharField(max_length=255, default='')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
class Meta:
ordering = ['invoice_number', ]
def __str__(self):
return self.invoice_number
def get_absolute_url(self):
return reverse("accounting:invoices:detail", kwargs={"pk":
self.pk})
}}}
right now the user has to put in the invoice number themselves. I want to not give the user that option though - I'd like to autofill that field in the database with a concatenation of the 2 digit year (17) plus 2 digit month (07) plus 2 digit day (24) and then a 2 digit auto increment for every invoice created on that specific date so the first invoice created today would be 17072401 and the second would be 17072402, etc. I'm guessing I need a field just for the date and another for the iteration of each invoice.
Can anyone give me some direction on this? First I'm not sure how to autofill a field in the database without getting the input from the user, and I'm also not sure how I would do the concatenation with the right numbers. Thanks for your help