我将管理员应用程序移植到前端需要做些什么? [英] What do I need to do to port an admin application to frontend?
问题描述
编辑Jonathan Fingland的评论
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
对于一个简单的搜索页面,您要制作一个包含表单的模板。将有一个搜索查询的文本框。 提交按钮将有一些网址作为其目标。该URL将对应于视图功能。而视图函数将使用用户键入的文本,执行数据库查询,最后得到一个Lawyer对象列表。
对于结果:搜索视图功能将呈现模板。它会发送一些数据,其中包括(可能除其他外)律师对象的列表。然后,在您的结果模板中,您只需循环浏览列表中的所有律师,并以HTML形式显示。 (例如:对于每个律师,< li>姓,名:公司< / li>
)。
我没有给你特定的代码,因为它有相当数量的写,它将取决于你的实现。这应该给你一个如何开始的想法...现在去阅读一些文档和示例!我确信你可以googledjango search form找到一个很好的例子。
编辑:这是Django书中的一个实际例子,它引导您完成搜索页面。
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.
这篇关于我将管理员应用程序移植到前端需要做些什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!