class DriverWorkDay(models.Model):
..................
@property
def days(self):
days = []
if self.monday:
days.append('понидельник')
if self.tuesday:
days.append('вторник')
if self.wednesday:
days.append('среда')
if self.thursday:
days.append('чтверг')
if self.friday:
days.append('пятница')
if self.saturday:
days.append('суббота')
if self.sunday:
days.append('воскресенье')
days = ', '.join([str(x) for x in days])
time = f'(С {self.time_from} по {self.time_to})'
return f'({self.driver.user.last_name} {self.driver.user.first_name} -- {days}, {time})'
class DriverWorkDayAdmin(admin.ModelAdmin):
list_display = ('driver', 'get_work_days', 'get_times')
def get_work_days(self, obj):
return obj.days
............
response = client.get('/categories/')
response.context['name']
response = client.get('/categories/')
response.json()['name']
app = Celery('app', broker='redis://localhost:6379/1',
backend='redis://localhost:6379/1', include=['app.tasks'])
class Category(models.Model):
pass
class Book(models.Model):
categories=models.ManyToManyField(Category)
CELERY_BEAT_SCHEDULE = {
'task_name': {
'task': 'app.module.task_name',
'schedule': timezone.timedelta(minutes=1),
}
}
from celery import shared_task
@shared_task
def task_name(*args, **kwargs):
pass
celery beat -A app_name -l info
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
MEDIA_URL = '/media/'
urlpatterns = + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
server {
listen 80;
server_name www.fasad.biz, fazad.bit;
return 301 https://fazad.bit$request_uri;
}
class M2M(models.Model):
developer = models.ForeignKey('Developer', on_delete=models.CASCADE)
project = models.ForeignKey('Project', on_delete=models.CASCADE)
class Meta:
db_table = "m2m"
class DataDetailSerializer(serializers.HyperlinkedModelSerializer):
item = ItemSerializer()
data = DataSerializer()
class Meta:
model = DataDetail
fields = ('data', 'name', 'data')
http {
upstream server1 {
server unix:///home/.../server1.sock;
}
upstream server2 {
server unix:///home/.../server2.sock;
}
server {
listen 80;
server_name server1.ru;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
uwsgi_pass server1;
include /etc/nginx/uwsgi_params;
}
}
server {
listen 80;
server_name server2.ru;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
uwsgi_pass server2;
include /etc/nginx/uwsgi_params;
}
}
}