Django admin output extra HTML in ModelSite - django

Ultimately, I want to add an <iframe> to the display of a particular model on Django's admin page. Django is already rendering the form for this model correctly, but I want to add this <iframe> in addition to Django's form. The src attribute needs to involve the primary key for the currently-displayed record.
I've learned how to properly override the change_form.html template through Django's documentation, and I can add markup to the right block, but I can't figure out how to access the primary key value. (No amount of determined Googling has helped at all.)
Alternatively, is there a direct way to specify that I want to produce extra output in my ModelSite definition?

Overriding "change_form.html" is the right way to go. You can access the current object with
{{ original }}

Related

Sitecore 6 WFFM: How to hide fields?

In Web Forms for Marketers, I have a few fields that I am using to pass values to the pipeline processors and to append CSS code to the form.
I don't want these fields to appear on the form. How can I mark a field to be invisible? Right now I am doing this via CSS, but I am quite sure there must be a better way to do so.
Thanks!
You can extend the Single Line Text field class and change the container CSS class to your own CSS class that hides the field and label. You can also add value to that field when the form is loaded through the querystring.
I believe there is a Hidden Field type in WFFM. Could you use that?

overriding admin field label content in django

I am using admin forms for the CRUD operations. However, I want to add certain characters in the labels generated by the admin. For example, * in case the field is required. How can I accomplish it?
I can directly go into django admin code and add the * in there (in the file contrib/admin/helpers.py in this case) But it is not the right way. How can I do it?
There's no "great" way to do this, so your options will be css (add background img), subclassing form, template tags, or template modification. There are some good answers to this previous question here:
How to render form field with information that it is required

Is it necessary to fill action attribute in django template form if using Generic View

I am using django Generic views which straigt way loads the create form.
I have seen that even if i don't enter anything in template form action attribute , the data still gets in database.
So i want to know that how does django know show to enter stuff in database
POSTing to the same URL does not require the action attribute to be specified, and omitting it altogether is the best solution.

Django: Display existing image with an instantiated ModelForm, rather than a file input?

I have some images assigned to an ImageField on several saved model instances. I want to display a ModelForm based on the model of interest, only for the purpose of setting one foreign key on the model. I'm instantiating the ModelForm with the model I want to edit.
All I'd like to do is display the existing image for the model along with the FK select. It would be easy enough to do both separately, but as I am actually displaying multiple forms side by side, within a {% for form in forms %} loop, I want to get the image displayed using something along the lines of <img src="{{ form.image.get_image_url }} />. I don't believe any template syntax like this exists for ImageField's on forms, but hopefully you catch my drift.
This seems like it should be a trivial exercise, but I haven't found a clear answer in the documentation or elsewhere. There was a suggestion on some forum threads that creating a custom field Widget might be the recommended solution, mostly with regards to customizing the admin, but I can't sort out the details of exactly how I should do this in my case on the site front-end. Thanks in advance for any hints.
You can access the model object associated with a ModelForm (provided such an association exists) using form.instance. From there you can access the image as you normally do.

Django-admin with callable functions

Django-admin view allows only for changing the values of model objects. Is it, however, possible to configure or change in an easy way the admin view so that it starts exposing functions on objects? I'm not talking about the functions that can be introduced in the drop-down menu on top of the object list. What I mean is a direct access to functions on model objects?
You can add your own view to the admin site by adding an "^admin/..." url in your url conf. You can use this to extend the admin site relatively easy and expose model methods through your own view. See Creating Custom Admin Views here: http://www.djangobook.com/en/1.0/chapter17/ (and another approach and notes here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites ).
To add this as a button in the model's "change form" in the admin site, override the change_form.html template for the required models (see https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates ).
You will probably want to override the object-tools block, which holds the buttons in the top right side of the page. (In Django 1.3 you can extend the object-tools-items block instead, see: https://code.djangoproject.com/ticket/12694 )
(I am quite sure one can build a nice plugin/app that automatically adds object-tools to a model from a custom "object_tools" property in the ModelAdmin with a list of model methods. Let me know id you find something like this.)