Hello all,
I am just starting learning Django and managed to get a basic website
working with a nice admin section. I am now facing a problem which I am not
sure how to resolve.
So I basically have 2 tables in my database:
- Flat
- PendingFlat
The PendingFlat would be a subset of the Flat table.
The website will offer the ability to a user to sell his flat. The website
will ask only a few questions to the user such as the price and the
location and store this information within the PendingFlat table. The admin
can then go the admin section of the website, view all pending flats from
the PendingFlat table and approve them as he wish. So I'd like to have an
approve button next to each line of the records of the PendingFlat table.
This button should then get the admin to the add view page of the Flat
table with some prepopulated fields such as the location and the price.
My first attempt was to do the following in the admin.py file:
class PendingFlatAdmin(admin.ModelAdmin):
def button(self, obj):
return mark_safe('<a
href="../flat/add/?rent={obj.rent}">Approve</a>'.format(obj=obj))
button.short_description = 'Approve'
button.allow_tags = True
list_display = ('id', 'button')
admin.site.register(PendingFlat, PendingFlatAdmin)
This will successfully get the admin to the add flat page with the rent
being prepopulated. Unfortunately, this won't delete the PendingFlat entry
once the admin has successfully added this flat to the database and it also
makes it difficult to maintain when new attributes are being added to the
table. Is there a nice way to achieve this?
I understand that my choice of database structure might be wrong. It might
be better to have a single table Flat which has a pending boolean field.
But if I do this how can I mark certain felds as being optional (blank =
True) when the pending field is set to True?
Thanks,
a noob who hopes to lose his noob status as soon as possible [image: :)]
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/N_1oRVhzIXEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.