After each test, Django calls flush to reset the database state. This empties all tables and emits the post_migrate signal, which recreates one content type and four permissions for each model. This operation gets expensive proportionally to the number of models.
Setting reset_sequences = True on a TransactionTestCase will make sure sequences are always reset before the test run
class TestsThatDependsOnPrimaryKeySequences(TransactionTestCase):
reset_sequences = True
def test_animal_pk(self):
lion = Animal.objects.create(name="lion", sound="roar")
# lion.pk is guaranteed to always be 1
self.assertEqual(lion.pk, 1)
url_ = f"{reverse("products")}"/add?pk_order={order_pk}&pk_repairer={i[0]}"
# settings.py
YOUR_SITE_BASE_URL = os.getenv('YOUR_SITE_BASE_URL')
from django.conf import settings
url_ = f"{settings.YOUR_SITE_BASE_URL}/add?pk_order={order_pk}&pk_repairer={i[0]}"
@receiver(post_save, sender=User)
def create_or_update_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
# тут если надо что-то делаем с моделью
instance.profile.save()
<slug:proj_slug>
и < int:pk>
:path('project/<slug:proj_slug>/comment/<int:pk>/edit', EditComment.as_view(), name='edit_comment')
{% url 'edit_comment' comment.pk %}
get_object
<slug:proj_slug>
и не делай мозг:path('project/comment/<int:pk>/edit', EditComment.as_view(), name='edit_comment')
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
return HttpResponseRedirect(request.path_info)
return reverse('post', kwargs={'post_pk': self.pk})
path('post/<int:post_pk>/', post_detail, name='post_detail'),
Не полностью подключается css к html(Django)?
Должна выходить page not found, но не поолучается
If a view is using this mixin, all requests by non-authenticated users will be redirected to the login page or shown an HTTP 403 Forbidden error, depending on the raise_exception parameter.
<a href="{% url 'profile' slug=user.userprofile.slug %}">Профиль {{ user.username }}</a>
collectstatic
до этого делал.relation "blog_userprofile" does not exist
{% load static %}
<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
<img src="{% static 'pages/image/facebook.png' %}" >
from django.db import models
from django.contrib.postgres.fields import CITextField
class YourModel(models.Model):
Tag = CITextField()