Inlines in the "forward direction" for OneToOneFields
Hello,
-- This is a tricky question that's been bothering me for over a year.
I'm working with french historians on a project called Dezède (source on github). For several models they need to specify one or two "spatiotemporal coverage(s)": when and where something happened. And sometimes they don't have exact dates|places, so they need CharFields to specify such approximations. And sometimes they just have a date without a place, etc.
So I ended up with models similar to those you can find below. (Sorry, it's a bit complex, but I promise it's simpler than the originals)
But this has a flaw.
When a user wants to specify Person.birth, he has to click on the magnifying glass, a popup opens with all the SpatioTemporalCoverages he can't choose (because of the OneToOneField), and he finally creates a new one.
That's awkward.
If he wants to modify it, it's even more complex, so that creating a new one is the best solution.
That's even awkwarder.
My question is therefore:
Is there a way to edit these SpatioTemporalCoverages directly from other admin change forms (Person, Work and Event)?
The closest solution I found is django-formfield.
Thanks!
Bertrand Bordage
# models.py
from django.db.models import *
class Place(Model):
name = CharField(max_length=200)
class SpatioTemporalCoverage(Model):
date = DateField(blank=True, null=True)
time = TimeField(blank=True, null=True)
place = ForeignKey(Place, blank=True, null=True)
approx_date = CharField(max_length=200, blank=True)
approx_time = CharField(max_length=200, blank=True)
approx_place = CharField(max_length=200, blank=True)
class Person(Model):
first_name = CharField(max_length=200)
last_name = CharField(max_length=200)
birth = OneToOneField(SpatioTemporalCoverage, blank=True, null=True)
death = OneToOneField(SpatioTemporalCoverage, blank=True, null=True)
class Profession(Model):
name = CharField(max_length=200)
class Author(Model):
person = ForeignKey(Person)
profession = ForeignKey(Profession)
class Work(Model):
title = CharField(max_length=200)
subtitle = CharField(max_length=200, blank=True)
authors = ManyToManyField(Author, blank=True, null=True)
creation = OneToOneField(SpatioTemporalCoverage, blank=True, null=True)
class Event(Model):
start = OneToOneField(SpatioTemporalCoverage)
end = OneToOneField(SpatioTemporalCoverage, blank=True, null=True)
works = ManyToManyField(Work)
# admin.py
from django.contrib.admin import ModelAdmin, site
from .models import *
class PersonAdmin(ModelAdmin):
raw_id_fields = ('birth', 'death')
class WorkAdmin(ModelAdmin):
raw_id_fields = ('creation',)
class EventAdmin(ModelAdmin):
raw_id_fields = ('start', 'end')
site.register(Place)
site.register(SpatioTemporalCoverage)
site.register(Person, PersonAdmin)
site.register(Profession)
site.register(Author)
site.register(Work, WorkAdmin)
site.register(Event, EventAdmin)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home