images = models.ManyToManyField(Image, related_name="auto_list")
main_image = models.OneToOneField(Image, related_name="auto")
sudo apt-get install python-pip
sudo ln -s /usr/lib/python3.4/configparser.py /usr/lib/python3.4/ConfigParser.py
sudo apt-get install libmysqlclient-dev python3-dev
sudo pip3 install MySQL-python
Насколько я понимаю, для python в этой сфере дела гораздо хуже чем для php или даже ror...
# urls.py
url(r"^/show-all/(?P<pk>\d+)/", some_view, name='show_all' ),
url(r"^/rozdil/(?P<pk>\d+)/", some_view1, name='rozdil' ),
url(r"^/name-part/(?P<pk>\d+)/", some_view2, name='name_part'),
# models.py
class NamePart(models.Model):
title = models.CharField(max_length=255,verbose_name=" .")
def get_absolute_url(self):
# используй
# https://docs.djangoproject.com/en/1.8/topics/http/urls/#reverse-resolution-of-urls
return reverse('name_part', self.id)
def __unicode__(self):
return u'%s' % (self.title)
class Rozdil(models.Model):
title = models.CharField(max_length=255,verbose_name="Налу")
part_of = models.ForeignKey(NamePart,verbose_name="н")
is_main = models.BooleanField(default=1,verbose_name="Гоний ?")
def get_absolute_url(self):
return reverse('rozdil', self.id)
def __unicode__(self):
return u'%s' % (self.title)
#views.py
def some_view(request):
foo = []
for name_part in NamePart.objects.all():
foo.append({
'name_part': name_part,
'rozdils': Rozdil.objects.filter(part_of=name_part.pk)
})
return render(request, 'template_show_all.html', {'foo': foo})
# template_show_all.html
{% for buzz in foo %}
<h1>{{ buzz. name_part.title}}
{% for bar in buzz.rozdils %}
<h2>{{ bar.title }}
{% endfor %}
{% endfor %}