These are chat archives for django/django

2nd
Nov 2016
Prabhjyotgambhir
@Prabhjyotgambhir
Nov 02 2016 07:08 UTC
Hi
Please if someone is online and is fimiliar with django
plzz reply asap
Filip Figiel
@megapctr
Nov 02 2016 10:16 UTC
@Prabhjyotgambhir what's up?
Jourdan Rodrigues
@jourdanrodrigues
Nov 02 2016 12:09 UTC
@Prabhjyotgambhir I'm here, too.
Sherif O.
@shadowsyntax
Nov 02 2016 21:02 UTC
how do i check if a database table is empty then if true do some other operations
Jourdan Rodrigues
@jourdanrodrigues
Nov 02 2016 21:10 UTC
Tables are represented by Models.
So...
if not ModelName.objects.exists(): do_something();
Sherif O.
@shadowsyntax
Nov 02 2016 21:12 UTC
thanks… but could i do something like this?
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 + 1
      form.save()
  except RefGen.DoesNotExist:
    if form.is_valid():
      form.save()

  return render(request, 'cusrefgen/index.html', {'form': form})
Sherif O.
@shadowsyntax
Nov 02 2016 21:18 UTC
@jourdanrodrigues thanks for the assistance.