These are chat archives for django/django

Nov 2016
Nov 17 2016 07:27
you can find related apps in pypi
Nov 17 2016 09:32
can anyone help me with this?
Sherif O.
Nov 17 2016 10:30

I have a model class defined as

class RefGen(models.Model):
    letter_date = models.DateField(
    dispatch_date = models.DateField()
    to_whom = models.CharField(max_length=50)
    letter_subject = models.CharField(max_length=100)
    org_units = models.CharField(max_length=50, choices=DEPARTMENTAL_NAMES)
    ref_number = models.IntegerField(default=0000)

and in my views file i have the following.

def form(request):
  form = RefGenForm(request.POST or None)
    temp = RefGen.objects.filter(ref_number__isnull=False).latest('ref_number')
    if form.is_valid():
      RefGen.ref_number = temp.ref_number + 1
  except RefGen.DoesNotExist:
    if form.is_valid():

The issue i have is when i try to increment RefGen.ref_number in my model I always get he default 0 set in the model. How to ref_number variable increment and be saved in the db

Mark Heppner
Nov 17 2016 14:16
@Ismael-VC if you’re really wanting a true auto incrementing value that starts at a different point, do it on the SQL level. in MySQL, it’s something like this ALTER TABLE tablename AUTO_INCREMENT = 7000;
@shadowsyntax you’re not saving the RefGen model, only the form. Plus, you’re setting the value in the class and not on an instance. After you get temp = RefGen.objects.filter(…), you need to set temp.ref_number += 1;
Ismael Venegas Castelló
Nov 17 2016 14:26
@mheppner thank you! Since I'm trying to learn Django mainly I didn't bother with MySQL and went ahead with SQLite, I think I can't do something homologous in SQLite.
Mark Heppner
Nov 17 2016 14:29
@Ismael-VC maybe something like this
Ismael Venegas Castelló
Nov 17 2016 15:40
Wow thanks for pointing me there, I'll try that :+1:
Miracle Ayodele
Nov 17 2016 15:53
@mheppner do u mind chatting u privately?
i am working on a custom user model, for authentication, it's not giving me any error and its not doing anything
Mark Heppner
Nov 17 2016 17:01
@koderNeptune yeah sure