Hi,
I have a model called ObjetArchi.
The primary key field looks like this:
id_objet_archi = models.AutoField(primary_key=True)
As for my previous messages, I’m working on a legacy database. The primary key field already existed, hence the custom name.
When I try to add a new object through the admin form, the auto increment doesn’t seem to work and the following error appears:
null value in column “id_objet_archi” of relation “objetarchi” violates not-null constraint
I first set id_objet_archi
as an IntegerField but the auto increment didn’t work either, so I was looking for the appropriate type.
Here is admin.py
:
from django.contrib.gis import admin
from django.contrib.gis.geos import Point
from .models import Illustrations, Materiau, ObjetArchi, Pays, ProvinceAntique, Region, Ville, Monument, CiteAntique, SiteAntique, Ensemble
class IllustrationsAdmin(admin.ModelAdmin):
search_fields = ('legende', 'lien')
class IllusInline(admin.TabularInline):
model = Illustrations
fields = ('images', 'legende', 'principale')
class ObjetArchiAdmin(admin.OSMGeoAdmin):
list_display = ('titre', 'date')
search_fields = (
'titre',
'prov_pays__nom',
'prov_region__nom',
'prov_departement__nom',
'prov_ville__nom',
'cons_pays__nom',
'cons_region__nom',
'cons_departement__nom',
'cons_ville__nom',
'materiau__nom'
)
autocomplete_fields = ('prov_pays', 'prov_region', 'prov_departement','prov_ville', 'cons_pays', 'cons_region', 'cons_departement', 'cons_ville', 'materiau', 'ensemble', 'provinceantique', 'siteantique', 'citeantique', 'monument')
exclude = ('id_objet_archi','lien_pdf', 'reference', 'version', 'observations', 'ref_repro', 'issn_objetarchi', 'flag_soumission_comite', 'lat', 'lon', 'cons_lieu', 'flag_del_objetarchi')
inlines = (
IllusInline,
)
pnt = Point(5.855572,47.019214, srid=4326)
pnt.transform(900913)
default_lon, default_lat = pnt.coords
class PaysAdmin(admin.ModelAdmin):
search_fields = ['nom']
class RegionAdmin(admin.ModelAdmin):
search_fields = ['nom']
class DepartementAdmin(admin.ModelAdmin):
search_fields = ['nom']
class VilleAdmin(admin.ModelAdmin):
search_fields = ['nom']
class PAntiqueAdmin(admin.ModelAdmin):
search_fields = ['nom']
class SAntique(admin.ModelAdmin):
search_fields = ['nom']
class CAntique(admin.ModelAdmin):
search_fields = ['nom']
class MateriauAdmin(admin.ModelAdmin):
search_fields = ['nom']
class EnsembleAdmin(admin.ModelAdmin):
search_fields = ['nom']
class MonumentAdmin(admin.ModelAdmin):
search_fields = ['nom']
admin.site.register(ObjetArchi, ObjetArchiAdmin)
admin.site.register(ProvinceAntique, PAntiqueAdmin)
admin.site.register(CiteAntique, CAntique)
admin.site.register(SiteAntique, SAntique)
admin.site.register(Pays, PaysAdmin)
admin.site.register(Region, RegionAdmin)
admin.site.register(Departement, DepartementAdmin)
admin.site.register(Ville, VilleAdmin)
admin.site.register(Monument, MonumentAdmin)
admin.site.register(Materiau, MateriauAdmin)
admin.site.registr(Ensemble, EnsembleAdmin)
admin.site.register(Illustrations, IllustrationsAdmin)
Is there something obviously wrong that I missed?
Thanks for your help!