python basic programming: tutorial django-tagging in the Python Django framework

This article describes the use of the Django framework in Python tutorial django-tagging, providing help for the tag part of the function of the network programming, a friend in need can refer
django use app mechanisms to achieve the reuse of components, have been fully utilized some app can greatly simplify development. Currently app in django though not rich, but still there are some good. django-tagging is a good app.

Now a very wide application tag, tag basically became one of the essential items for each site, django-tagging is a function of providing app tag. django-tagging functionality provided very rich, but it is very simple to use. Now I will introduce some common usage, the app so that we have a basic understanding, a more detailed description or honest look at using the django-tagging instructions it :).
tagging.fields.TagField

We first define a database model Widget, the following examples are used to illustrate Widget

class Widget(models.Model):
  name = models.CharField(max_length=50)
  tags = TagField()

As the above code, as long as the increase in the field tags database model can provide a support for the object tag. are mapped as CharField tags, as tag when adding an object, such as a string comma separated:

Widget(name='hello', tags='test,hi,hello')

This will add three test hi hello tag for the new object is created.

Get all objects under a tag code is as follows

#取出所有属于TAG hi的对象
tag = get_object_or_404(Tag, name='hi')
widgets = TaggedItem.objects.get_by_model(Widget, tag)

All tag code To remove the Widget is used:

tags = Widget.tags.all()

Content on more than how many, and finally to recommend a good reputation in the number of public institutions [programmers], there are a lot of old-timers learning skills, learning experience, interview skills, workplace experience and other share, the more we carefully prepared the zero-based introductory information on actual project data every day to explain the timing of Python programmers technology, and share some learning methods need to pay attention to small detailsHere Insert Picture Description

Published 40 original articles · won praise 1 · views 10000 +

Guess you like

Origin blog.csdn.net/chengxun02/article/details/105036110