These are chat archives for django/django

17th
Nov 2016
Slava
@scream4ik
Nov 17 2016 07:27 UTC
you can find related apps in pypi
Roel
@roelzkie15
Nov 17 2016 09:32 UTC
can anyone help me with this?
Sherif O.
@shadowsyntax
Nov 17 2016 10:30 UTC

I have a model class defined as

class RefGen(models.Model):
    letter_date = models.DateField(default=timezone.now)
    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)
  try:
    temp = RefGen.objects.filter(ref_number__isnull=False).latest('ref_number')
    if form.is_valid():
      RefGen.ref_number = temp.ref_number + 1
      form.save()
  except RefGen.DoesNotExist:
    if form.is_valid():
      form.save()

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
@mheppner
Nov 17 2016 14:16 UTC
@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; temp.save().
Ismael Venegas Castelló
@SalchiPapa
Nov 17 2016 14:26 UTC
@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
@mheppner
Nov 17 2016 14:29 UTC
@Ismael-VC maybe something like this
Ismael Venegas Castelló
@SalchiPapa
Nov 17 2016 15:40 UTC
Wow thanks for pointing me there, I'll try that :+1:
Miracle Ayodele
@iammiracle
Nov 17 2016 15:53 UTC
@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
@mheppner
Nov 17 2016 17:01 UTC
@koderNeptune yeah sure