python,django,django-admin,django-admin-filters,django-admin-tools
Define a function to generate invoice number. def increment_invoice_number(): last_invoice = Invoice.objects.all().order_by('id').last() if not last_invoice: return 'MAG0001' invoice_no = last_invoice.invoice_no invoice_int = int(invoice_no.split('MAG')[-1]) new_invoice_int = invoice_int + 1 new_invoice_no = 'MAG' + str(new_invoice_int) return new_invoice_no Now use this function as default value in your model filed. invoice_no = models.CharField(max_length =...
python,django,inline,django-queryset,django-admin-filters
Use the get_queryset method: https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset Should look like: class BAdmin(admin.TabularInline): ... def get_queryset(self, request): qs = super(BAdmin, self).get_queryset(request) return qs.filter(user=request.user) ...
python,django,sqlite,django-admin,django-admin-filters
I found out the answer. If you are filtering on one reverse ForeignKey relationship (apps__category in this case) everything works fine. But I forgot to mention that I am combining two filters at the right side of Django admin page - the other one is also a reverse ForeignKey -...
python,django,django-admin,django-admin-filters
Firstly, you can use the applications api to get a list of models in your app, rather than inspecting the module's __dict__ In Django 1.8+, you can get a list of field names for a model using Model._meta.get_fields method. I've excluded the automatically generated id field, and you might find...