What is the right way of containing data in django? - django

I'm rebuilding school project from html page to django app. In old project I had some articles and two tests.
For articles I created django model with text field and pasted in it article's content with HTML due to it have some decorations as a <"code> <"/code> tags.
How should I contain tests if first is build with HTML forms and second with <"canvas>? Should I use text field again? Data is too complex. For the first test it goes as a forms with individual texts and inputs and checked by javascript. For second it is initializing js functions.
How they are look like:
First test with forms
Second test with canvas
Where can I read about it more?
P.S. Sorry for bad english

Related

Django: displaying all fields of all tables, the dumbest view possible

I've inherited a Django PostGres application with a model containing around 40 tables.
I've redesigned the model from head to toe, and now I'm setting in to re-build the web front end. I haven't used Django previous to this project - and no HTML for many years - but I'm happy enough with the ORM end of Django.
As a raw default, I just wanted to display all the fields of a class on an individual html page. Any references (i.e. ForeignKeys, or ManyToOne references) should appear as html links to another html page, which displays that class' data.
The application that I've inherited does more or less that, but uses about 50 modules containing hundreds of boiler-plate views, forms, and serializers - absolutely none of which contain anything remotely intelligent in. The "active" code on each form just sayd 'all'.
Rather than autogenerate this code (yuk!), is there a quick way of asking Django to display a basic tabular view unless there is a bespoke view for the table?

Django form with autocomplete functionality

I am working on a django project with complex forms. In one of my form fields I need following functionality...... Its the text field. As the user starts typing the value the suggestions from existing database should appear in dropdown. Can anyone help me out with this ? Just similar to autocomplete but able to add new values.
This is going to be something in the JQuery/AJAX side of things, not Django. I would read up on the autocomplete functions of JQuery and use AJAX to call your DJango code and receive a populated list, which then displays to the user.
JQuery Autocomplete - Custom Data
If you don't want to deal with JavaScript, you can use a django application called django-autocomplete-light.
You can learn more about it (and get it) here: https://github.com/yourlabs/django-autocomplete-light

Split form into tabs in Django

I'm developing a Django app which has database driven form fields. I've followed this guide which seems to work so far.
I'm using Twitter Bootstrap and would like to split my fields into tabs. What would be the Django way to do this? Should I append the group label to the id of the form fields and somehow do the magic in the template? Should I use multiple forms in the same view (seems complicated)?
The end result HTML wise is to enclose the input fields in the correct div elements with the group's id like so.
I recently required the very same thing.
After some research, I used django-crispy-forms, which worked quite well. A more detailed instructions about the tabs (and the need of .js file for animation) can be found here, in the 'tabs' section.

How to access page title in Django templates?

How can I get the page title in the template? I know there are ways to do this with javascript, but I'll prefer a template-tag or a variable if it exists.
The page title is an html element (<title>Title Here</title>), and django has no idea what that is.
Django's templates render the raw HTML text, which a browser parses and only then does the concept of a page title exist for javascript to parse.
If you need it in django, you'd want to ensure django is building that title tag and you would access it in the same way you'd display any other variable in a template.
It's probably best left to the DOM tools since a title might be created in any number of ways. If you absolutely need it in django, I would probably parse the final rendered HTML with an HTML parser like BeautifulSoup.
title = BeautifulSoup(mytemplate.render(Context({}))).html.head.title

How customize fields in the Django admin interface

I have a model in my Django project with a member which is a char field. Basically data in this field will be entered as comma-separated values.
Without a long-winded explanation of what the overall goal of this is, basically rather than having the admin interface use a simple text field, I'd rather have have some custom HTML for the form so I can just use checkboxes and assemble the values of the checked boxes into a CSV string myself once the form is submitted.
Most of the django customization I was able to find on Google didn't answer my particular problem.
If I understand your question correctly I think you want to search for writing custom widgets. Perhaps start here: http://docs.djangoproject.com/en/dev/topics/forms/