Commit 6d7bcc9c authored by freetux's avatar freetux

some fixes in database

parent da1b2d50
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-10-10 09:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('body', '0007_gbw'),
]
operations = [
migrations.CreateModel(
name='Food',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255, null=True, verbose_name='نام')),
('amount', models.FloatField(verbose_name='مقدار')),
('unit', models.CharField(choices=[('GR', 'گرم'), ('LT', 'لیتر'), ('NM', ' عدد')], max_length=2, verbose_name='واحد اندازه گیری')),
('Calories', models.FloatField(verbose_name='کالری')),
('details', models.CharField(max_length=255, null=True, verbose_name='توضیح')),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-10-10 09:26
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('body', '0008_food'),
]
operations = [
migrations.RenameField(
model_name='food',
old_name='Calories',
new_name='calories',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-11-20 14:43
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django_jalali.db.models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('body', '0009_auto_20181010_1256'),
]
operations = [
migrations.CreateModel(
name='FoodProgram',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('breakfest', models.CharField(max_length=255, verbose_name='صبحانه')),
('bm', models.CharField(max_length=255, verbose_name='میان وعده صبحانه')),
('lounch', models.CharField(max_length=255, verbose_name=' نهار')),
('lm', models.CharField(max_length=255, verbose_name='میان وعده نهار')),
('dinner', models.CharField(max_length=255, verbose_name=' شام')),
('dm', models.CharField(max_length=255, verbose_name=' میان وعده شام')),
('date', django_jalali.db.models.jDateTimeField(null=True, verbose_name='تاریخ ایجاد')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -32,6 +32,18 @@ class Drug(models.Model):
remarks = models.CharField(_("توضیحات"), max_length=255)
date = jmodels.jDateTimeField(_("تاریخ ایجاد"), null=True)
# this is for food program
class FoodProgram(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
breakfest = models.CharField(_("صبحانه"), max_length=255)
bm = models.CharField(_("میان وعده صبحانه"), max_length=255)
lounch = models.CharField(_(" نهار"), max_length=255)
lm = models.CharField(_("میان وعده نهار"), max_length=255)
dinner = models.CharField(_(" شام"), max_length=255)
dm = models.CharField(_(" میان وعده شام"), max_length=255)
date = jmodels.jDateTimeField(_("تاریخ ایجاد"), null=True)
#goal body weight
class Gbw(models.Model):
......@@ -71,7 +83,18 @@ class Rx(models.Model):
return "{}-{}-{}-{}".format(self.id, self.user, self.date_created, self.drugs)
class Food(models.Model):
UNIT_CHOICES = (
('GR', 'گرم'),
('LT', 'لیتر'),
('NM', ' عدد')
)
id = models.AutoField(primary_key=True)
name = models.CharField(_('نام'), max_length=255, null=True)
amount = models.FloatField(_('مقدار'))
unit = models.CharField(_('واحد اندازه گیری'), max_length=2, choices=UNIT_CHOICES)
calories = models.FloatField(_('کالری'))
details = models.CharField(_('توضیح'), max_length=255, null=True)
......
......@@ -3,8 +3,8 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from users.models import User
from django.conf import settings
from body.models import Weight, Gbw, Drug
from body.models import Weight, Gbw, Drug, Food, FoodProgram
from django_select2.forms import Select2MultipleWidget
class UserCreationForm(forms.ModelForm):
email = forms.EmailField(label='ایمیل', max_length=255)
......@@ -64,6 +64,29 @@ class GbwCreateForm(forms.ModelForm):
model = Gbw
fields = ('gbw',)
class FoodCreateForm(forms.ModelForm):
"""
Use to create Food
"""
class Meta(object):
model = Food
fields = ('name','amount', 'unit', 'calories', 'details')
class FoodProgramForm(forms.ModelForm):
"""
this is for food program
"""
breakfest = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
bm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
lounch = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
lm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
dinner = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
dm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
class Meta(object):
model = FoodProgram
fields = ('breakfest','bm', 'lounch', 'lm', 'dinner','dm')
class UserAdminCreationForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
......
from django.conf.urls import url
from sites import views
from body.models import Weight, Drug
from users.models import User
from body.models import Weight, Drug, Food
......@@ -23,6 +22,16 @@ urlpatterns = [
url(r'^rx/$', views.RxView.as_view(), name='rx'),
url(r'^goal/$', views.GoalView.as_view(), name='goal'),
url(r'^goal/create$', views.GoalCreate.as_view(), name='gbw_create'),
url(r'^program/create$', views.FoodProgramCreate.as_view(), name='program_create'),
url(r'^food/$', views.FoodList.as_view(), name='food_list'),
url(r'^food/create$', views.FoodCreate.as_view(), name='food_create'),
url(r'^food/(?P<pk>[\w]+)/$', views.FoodShow.as_view(), name='food_show'),
url(r'^food/update/(?P<pk>[\w]+)/$', views.FoodUpdate.as_view(
model=Food,
), name='food_update'),
url(r'^food/delete/(?P<pk>[\w]+)/$', views.FoodDelete.as_view(
model=Food,
), name='food_delete'),
url(r'^drug/$', views.DrugList.as_view(), name='drug'),
url(r'^drug/create$', views.CreateDrug.as_view(), name='drug_create'),
url(r'^weight/create$', views.WeightCreate.as_view(), name='weight_create'),
......
......@@ -2,11 +2,11 @@ from django.shortcuts import render, redirect
from django.template import loader
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic import TemplateView, CreateView, DetailView, UpdateView, DeleteView, ListView
from .forms import UserCreationForm, WeightCreateForm, ProfileUpdateForm, GbwCreateForm, DrugCreateForm
from .forms import UserCreationForm, WeightCreateForm, ProfileUpdateForm, GbwCreateForm, DrugCreateForm, FoodCreateForm, FoodProgramForm
from django.contrib.auth import login
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from body.models import Weight, Rx, Drug, Gbw
from body.models import Weight, Rx, Drug, Gbw, Food, FoodProgram
from django.http import JsonResponse
from django.template.loader import render_to_string
from users.models import User
......@@ -193,6 +193,63 @@ class DrugView(TemplateView):
context['drug'] = drug
return context
@method_decorator(login_required, name='dispatch')
class FoodProgramCreate(CreateView):
model = FoodProgram
form_class = FoodProgramForm
success_url = reverse_lazy('food_list')
@method_decorator(login_required, name='dispatch')
class FoodCreate(CreateView):
model = Food
form_class = FoodCreateForm
success_url = reverse_lazy('food_list')
@method_decorator(login_required, name='dispatch')
class FoodList(ListView):
model = Food
context_object_name = 'foods'
paginate_by = 10
@method_decorator(login_required, name='dispatch')
class FoodShow(DetailView):
model = Food
def get_queryset(self):
return self.model.objects
@method_decorator(login_required, name='dispatch')
class FoodUpdate(UpdateView):
model = Food
success_url = reverse_lazy('food_list')
form_class = FoodCreateForm
def get_queryset(self):
return self.model.objects
def get_initial(self):
initial = super(FoodUpdate, self).get_initial()
initial.update()
return initial
def form_valid(self, form):
"""Force the user to request.user"""
self.object = form.save(commit=False)
self.object.save()
return super(FoodUpdate, self).form_valid(form)
@method_decorator(login_required, name='dispatch')
class FoodDelete(DeleteView):
success_url = reverse_lazy('food_list')
def get_object(self, queryset=None):
""" Hook to ensure object is owned by request.user. """
obj = super(FoodDelete, self).get_object()
return obj
......
......@@ -57,6 +57,7 @@ INSTALLED_APPS = [
"pinax.messages",
'bootstrap3',
'usda_nutrition',
'django_select2',
]
JWT_AUTH = {
......@@ -109,7 +110,7 @@ WSGI_APPLICATION = 'tanbama.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbmysql',
'NAME': 'tanbama',
'USER': 'tanbama',
'PASSWORD': 'kshlug',
'HOST' : 'localhost',
......@@ -163,7 +164,7 @@ USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_TZ = False
import locale
locale.setlocale(locale.LC_ALL, "fa_IR")
......
......@@ -16,6 +16,7 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/', include(api_urls)),
url(r'^accounts/', include('users.urls')),
url(r'^select2/', include('django_select2.urls')),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
{% extends "sites/base_site.html" %}
{% load static %}
{% load jformat %}
{% block title %} تایید میکنید؟ {% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% block location %}
تایید میکنید؟
{% endblock location %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-md-4 center-block">
<div class="card-block mx-auto">
<form action="" method="post">{% csrf_token %}
<div class="alert alert-danger alert-dismissible fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>هشدار!</strong>
</br>
از حذف "{{ object }}" مطمئنید؟
</div>
<button type="submit" class="btn btn-danger ">تایید</button>
</form>
</div>
</div>
</div>
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
{% extends "sites/base_site.html" %}
{% load static %}
{% load jformat %}
{% block title %} جزئیات {% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% block location %}
جزئیات
{% endblock location %}
{% block content %}
<div class="container-fluid">
<div class="col-sm-6 col-md-4 offset-sm-4">
<div class="card">
<div class="card-header">
جزئیات
</div>
<div class="card-block">
<p>نام: {{ object.name }}</p>
<p>مقدار: {{ object.amount }}</p>
<p>واحد اندازه گیری: {{ object.unit }}</p>
<p>کالری: {{ object.calories }}</p>
<p>توضیح: {{ object.details }}</p>
</div>
</div>
</div>
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
{% extends "sites/base_site.html" %}
{% block title %}
{% if object_list %}
ویرایش ماده غذایی
{% else %}
افزودن ماده غذایی
{% endif %}
{% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% if object_list %}
{% block location %}
{% if object_list %}
ویرایش ماده غذایی
{% else %}
افزودن ماده غذایی
{% endif %}
{% endblock location %}
{% endif %}
{% block content %}
<div class="row">
<div class="col-md-4 offset-sm-4">
<div class="card">
<div class="card-header">
{% if object_list %}
ویرایش <strong> ماده غذایی </strong>
{% else %}
افزودن <strong> ماده غذایی </strong>
{% endif %}
</div>
<div class="card-block">
<form action="" method="post" enctype="multipart/form-data" class="form-horizontal ">{% csrf_token %}
{% if form.errors %}
{% include "users/partials/errors.html" %}
{% endif %}
{% csrf_token %}
{% for field in form %}
<div class="input-group m-b-1">
{% include "users/partials/field.html" %}
</div>
{% endfor %}
<div class="card-footer">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i>
{% if object_list %}
ویرایش
{% else %}
افزودن
{% endif %}
</button>
<button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> بازنشانی</button>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
\ No newline at end of file
{% extends "sites/base_site.html" %}
{% load static %}
{% load jformat %}
{% block title %} مواد غذایی {% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% block location %}
مواد غذایی
{% endblock location %}
{% block content %}
<!--/.container-fluid-->
<div class="container-fluid">
<div class="animated fadeIn">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<i class="fa fa-align-justify"></i> مواد غذایی
</div>
<div class="card-block">
<p>
<a class="btn btn-outline-primary" href="{% url 'food_create' %}" role="button">
<span class="fas fa-plus"></span>
افزودن جدید
</a>
</p>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>نام</th>
<th>واحد اندازه گیری</th>
<th>مقدار</th>
<th>کالری</th>
<th>جزئیات</th>
<th>مشاهده</th>
<th>ویرایش</th>
<th>حذف</th>
</tr>
</thead>
<tbody>
{% for food in foods %}
<tr>
<td>{{ food.id }}</td>
<td>{{ food.name }}</td>
<td>{{ food.unit}}</td>
<td>{{ food.amount|floatformat }}</td>
<td>{{ food.Calories|floatformat }}</td>
<td>{{ food.details }}</td>
<td><a href="{% url "food_show" food.id %}">مشاهده</a></td>
<td><a href="{% url "food_update" food.id %}">ویرایش</a></td>
<td><a href="{% url "food_delete" food.id %}">حذف</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">&laquo; قبل</a></li>
{% else %}
<li class="disabled"><span>&laquo; قبل</span></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="page-item"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">&raquo; بعد</a></li>
{% else %}
<li class="disabled"><span>&raquo; بعد</span></li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
</div>
<!--/col-->
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
{% extends "sites/base_site.html" %}
{% block title %}
{% if object_list %}
ویرایش برنامه غذایی
{% else %}
افزودن برنامه غذایی
{% endif %}
{% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% if object_list %}
{% block location %}
{% if object_list %}
ویرایش برنامه غذایی
{% else %}
افزودن برنامه غذایی
{% endif %}
{% endblock location %}
{% endif %}
{% block content %}
<div class="row">
<div class="col-md-4 offset-sm-4">
<div class="card">
<div class="card-header">
{% if object_list %}
ویرایش <strong> برنامه غذایی </strong>
{% else %}
افزودن <strong> برنامه غذایی </strong>
{% endif %}
</div>
<div class="card-block">
<form action="" method="post" enctype="multipart/form-data" class="form-horizontal ">{% csrf_token %}
{% if form.errors %}
{% include "users/partials/errors.html" %}
{% endif %}
{% csrf_token %}
{% for field in form %}
<div class="input-group m-b-1">
{% include "users/partials/field.html" %}
</div>
{% endfor %}
<div class="card-footer">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i>
{% if object_list %}
ویرایش
{% else %}
افزودن
{% endif %}
</button>
<button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> بازنشانی</button>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
\ No newline at end of file
......@@ -3,6 +3,9 @@
{% load i18n %}
{% load pinax_messages_tags %}
<!--
* CoreUI - Open Source Bootstrap Admin Template
* @version v1.0.0-alpha.2
......@@ -32,6 +35,7 @@
<link href="{% static "css/font-awesome.min.css" %}" rel="stylesheet">
<link href="{% static "css/simple-line-icons.css" %}" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
{{ form.media.css }}
{% block stylesheets %}
<!-- Main styles for this application -->
<link href="{% static "dest/style.css" %}" rel="stylesheet">
......@@ -200,6 +204,7 @@
<!-- Grunt watch plugin -->
<script src="//localhost:8009/livereload.js"></script>
{{ form.media.js }}
{% endblock javascripts %}
{% endblock body %}
......
{% extends "sites/base_site.html" %}
{% load static %}
{% load jformat %}
{% block title %} دارو های من {% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}