Re: How can I auto-fill a field in the model without showing a form field to the user?

2017-07-25 Thread ecas
One way could be to overload the save method of the model. Maybe something like this in your models.py: import datetime class Invoice(models.Model): def save(self, *args, **kwargs): if not self.id: today = datetime.date.today() date_str = datetime.dat

Re: Django Forms HorizontalRadioSelect Renderer not working.

2017-07-25 Thread ecas
Which version of Django are you using? From 1.11 the widgets changed to a template mechanism. https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#radioselect Maybe this can help: https://stackoverflow.com/questions/44187640/django-1-11-horizontal-choice-field El dimarts, 25 juliol de 2017

Re: how to display a foreign key image of an object in an object_list view/template?

2017-07-11 Thread ecas
n Tuesday, July 11, 2017 at 5:29:15 AM UTC-4, ecas wrote: >> >> >> You can query for the images, and keep the first one for the template >> rendering. >> >> products = Product.objects.all() >> for product in products: >> products.image = pro

Re: how to display a foreign key image of an object in an object_list view/template?

2017-07-11 Thread ecas
You can query for the images, and keep the first one for the template rendering. products = Product.objects.all() for product in products: products.image = product.productimages_set.first() -- You received this message because you are subscribed to the Google Groups "Django users" grou

Re: How to create a fixed-length binary field with a unique constraint?

2017-07-11 Thread ecas
I would use: fingerprint_sha256 = models.CharField(max_length=64, unique=True, db_index=True) In hexadecimal, a SHA-256 uses 64 characters (4 bits per char). The ASCII of the characters used in the hexadecimal representation are 1 byte in UTF-8 (0-9, a-f). -- You received this message because

Re: Django tutorial - Misleading instructions

2017-06-30 Thread ecas
As Tim said, the APP_DIRS flag enables the app template loader. https://docs.djangoproject.com/en/1.11/ref/templates/api/#django.template.loaders.app_directories.Loader "Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS

How to combine change_list_template in ModelAdmin mixin

2017-06-29 Thread ecas
I would like to create a mixin to extend the ModelAdmin class that adds a description text to the view, overriding the default change_list_template. [admin_extra.py] class DescriptionAdminMixin(object) change_list_template = "description_change_list.html" ... def changelist_view(self, reque