>>> from core.models import *
>>> t1 = Tariff.objects.get(pk=1)
>>> t1.channels_list
<django.db.models.fields.related_descriptors.create_forward_many_to_many_manager.<locals>.ManyRelatedManager object at 0x000002C0AA1D7580>
>>> t1.channels_list.all()
<QuerySet [<Channel: Первый канал (Основная)>, <Channel: Второй канал (Основная)>]>
>>>
w = Words.objects.create(word=data[0])
w.category, _* = Category.objects.get_or_create(category=data[1])
w.save()
class Model(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
@classmethod
def get_model(cls):
return cls.objects.filter(title__icontains="123")
from core.models import Model
Model.get_model()
<QuerySet []>
m1 = Model(title="123")
m1.save()
Model.get_model()
<QuerySet [<Model: 123>]>
class ModelBase(models.Model):
title = models.CharField(_("Название"), max_length=250, blank=False)
def __str__(self):
return self.title
class Model(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
class Model1(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
m = models.ForeignKey(Model, on_delete=models.CASCADE)
class Model2(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
m1 = models.ForeignKey(Model1, on_delete=models.CASCADE)
class Model3(ModelBase):
some = models.CharField(_("Что то "), max_length=250)
m2 = models.ForeignKey(Model2, on_delete=models.CASCADE)
from core.models import *
m1 = Model.objects.all()
m1[0].model1_set
<django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x00000296EFFAAE20>
m1[0].model1_set.all()[0].model2_set.all()[0].model3_set.all()[0].some
'some m3'
class SensorForm(ModelForm):
class Meta:
model = Sensors
fields = ['name ', 'x', 'y', 'h','sensors ']
from .forms import SensorForm
def sensortoroom(request, room_id):
room = Rooms.objects.filter(id=room_id)
form = SensorForm()
if request.POST:
pass
return render(request, 'room/addsensortoroom.html', {'form': form})