# Это курс - он связан с моделью юзера
class Course(models.Model):
days = models.IntegerField()
start_date = models.DateField()
user = models.ForeignKey(User)
# Это лекарство - оно само по себе
class Med(models.Model):
med = models.ChoiceField()
time = models.ChoiceField()
med_amount = models.CharField()
med_type = models.ChoiceField()
descr = models.TextField()
video = modesl.URLField()
week = models.ChoiceField()
# Это связывает курс с лекарством (и позволяет присваивать их неограниченное число раз)
class CourseMed(models.Model):
course = models.ForeignKey(Course)
med = models.ForeignKey(Med)
from django.contrib.sessions.middleware import SessionMiddleware
class MySessionMiddleware(SessionMiddleware):
def process_request(self, request):
if request.path_info.startswith('/static/'):
return None
super(MySessionMiddleware, self).process_request(request)
def process_response(self, request, response):
if request.path_info.startswith('/static/'):
return response
return super(MySessionMiddleware, self).process_response(request, response)
@register.filter
def distance(obj, coords):
return obj.get_distance(coords)
def get_distance(self, coords):
return self.calculate_distance(self.coords, coords)
# ^^^^ это ужасно сложный код подсчета дистанции
{% for object in object_list %}
{{ object|distance:coords }}
{% endfor %}
args['comments'] = Comment.objects.filter(comment_product_id=product_slug)
date_from = datetime.datetime.now() - datetime.timedelta(days=1)
args['comments'] = Comment.objects.filter(comment_product_id=product_slug, comment_created_at__gte=date_from).order_by('comment_created_at')
import datetime