Tutorial :What do I need to do to port an admin application to frontend?


I have a simple admin database. I want to port it to search and results pages. How do I achieve this? Thanks

EDIT re Jonathan Fingland's comment

from django.db import models    class Lawyer(models.Model):      firm_url = models.CharField('Bio', max_length=200)      firm_name = models.CharField('Firm', max_length=100)      first = models.CharField('First Name', max_length=50)      last = models.CharField('Last Name', max_length=50)      year_graduated = models.IntegerField('Year graduated')      school = models.CharField(max_length=300)        class Meta:          ordering = ('last',)      def __unicode__(self):          return self.first   


How much experience do you have with Django? If you have an admin-only site, perhaps you've only ever really worked with the model layer of Django's model-view-template architecture. I think you can answer your own question by reading the documentation and tutorials more thoroughly (check out djangobook.com). However, as an example to get you started:

For a simple search page, you want to make a template that has a form in it. There will be a text box for the search query. The "submit" button would have some url as its target. That URL will correspond to a view function. And view function will take the text that the user typed in, perform a database query, and end up with a list of Lawyer objects.

As for the results: this same search view function will render a template. It will send it some data, which will include (possibly among other things), the list of lawyer objects. Then, in your result template, you simply loop through all of the lawyers in your list and display them all somehow in HTML. (eg: for each lawyer, <li>Last name, first name: Firm</li>).

I'm not giving you specific code, because there is a fair amount of it to write and it will depend on your implementation. This should give you an idea of how to get started... now go read some documentation and examples! I'm sure you can google "django search form" and find a good example.

Edit: Here's an actual example in the Django book that walks you through making a search page.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »