我将管理员应用程序移植到前端需要做些什么? [英] What do I need to do to port an admin application to frontend?

查看:73
本文介绍了我将管理员应用程序移植到前端需要做些什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的管理数据库。我想将其移植到搜索和结果页面。我该如何实现?感谢



编辑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


解决方案你/ Django有多少经验?如果你只有一个只有管理员的站点,也许你只是真正使用了Django模型视图模板架构的模型层。我想您可以通过更详细地阅读文档和教程来回答自己的问题(请查看 djangobook.com ) 。但是,以让您开始的一个例子:



对于一个简单的搜索页面,您要制作一个包含表单的模板。将有一个搜索查询的文本框。 提交按钮将有一些网址作为其目标。该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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆