Install virtualenvwrapper, which eases the handling of Python virtualenvs (sort of Virtual Machines for Python packages).
$ pip3 install --user virtualenvwrapper
Add to your ~/.bashrc
, or better, to your ~/.bash_profile
:
/* | |
Da compilare su linux con: | |
gcc -o allocation_examples allocation_examples.c | |
oppure se si vuole usare il vecchio standard del C dell'89: | |
gcc --std=c89 -o allocation_examples allocation_examples.c | |
Si puo' poi eseguire facendo: | |
./allocation_examples | |
*/ |
Create a dir to build things into: | |
$ mkdir ~/stack && cd ~/stack | |
Download the sources (sqlite 3230100 was broken, 3220000 was used instead): | |
$ wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz | |
$ wget https://sqlite.org/2018/sqlite-src-3220000.zip | |
$ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz |
from django import forms | |
# https://github.com/django/django/blob/master/django/forms/widgets.py | |
class HTML5DateWidget(forms.widgets.Input): | |
input_type = 'date' | |
template_name = 'django/forms/widgets/date.html' | |
# Example: |
# --- forms.py --- | |
class CSVImportForm(forms.Form): | |
file = forms.FileField() | |
comment = forms.CharField(max_length=50, required=False) | |
# --- utils.py --- |
Manually provide the id with: | |
# forms.py | |
class SomethingForm(...): | |
id = forms.IntegerField(min_value=0) | |
# serializers.py | |
class SetIDFieldFromModel: | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) |
First of all, edit your_app_settings/settings.py
and add:
INSTALLED_APPS = [
'django.forms', # to let django discover the built-in widgets
...
]
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
Inside your application directory, create a file your_app/signals.py
.
The default project and app creator should have created a file your_app/apps.py
.
Inside the class used for your app, add the ready
method:
class YourAppConfig(AppConfig):
name = 'your_app'
def ready(self):
If we have a model with some fields that have default
values (e.g. a cost = DecimalField(default=0, null=false)
), and we receive a form with that field set as None
, django will complain with a NOT NULL constraint failed
.
We can manually set the fields of interest in the save()
method of the models, or simply add this class to all the django Models, which will automatically discover and set the null fields having a default value.
from django.db.models.fields import NOT_PROVIDED
class SetModelDefaultsOnSave:
def save(self):
for field in self._meta.get_fields():
if (not field.auto_created and getattr(self, field.name) is None and
24046 /usr/bin/ld: /opt/cluster/spack/opt/spack/linux-centos7-x86_64/gcc-8.2.0/boost-1.68.0-xkyf5icz7yn62yjvduwrs3mfru4merj4/lib/libboost_serialization-mt.a(archive_exception.o): re | |
location R_X86_64_32S against symbol `_ZTVN5boost7archive17archive_exceptionE' can not be used when making a shared object; recompile with -fPIC | |
24047 /usr/bin/ld: /opt/cluster/spack/opt/spack/linux-centos7-x86_64/gcc-8.2.0/boost-1.68.0-xkyf5icz7yn62yjvduwrs3mfru4merj4/lib/libboost_serialization-mt.a(basic_archive.o): reloca | |
tion R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC | |
24048 /usr/bin/ld: /opt/cluster/spack/opt/spack/linux-centos7-x86_64/gcc-8.2.0/boost-1.68.0-xkyf5icz7yn62yjvduwrs3mfru4merj4/lib/libboost_filesystem-mt.a(operations.o): relocation R | |
_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC | |
24049 /usr/bin/ld: /opt/cluster/spack/opt/spack/l |