Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Create a fake Database for testing API with wagtail

I need to create some tests against my APIs. APIs use wagtail pages and serve me the contents of them. I'm at the point of creating the database for the tests, but I'm not able to create wagtail pages, because I always get

ValidationError: {'path': [u'This field cannot be blank.'], 'depth': [u'This field cannot be null.']}

How can I do it? Do I have to create the entire site from the root down to the tree?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

depth - it's a nesting level. The ROOT page has level 1, the main page has level 2, Obviously, only 1 page can be on the first and second level

path - this is a specific value, which I have not yet understood.

The ROOT page (depth = 1) has this path: 0001,

The main page on the second nesting level (depth = 2) has the path 00010001.

The first page on the third nesting level (depth = 3) has the path 000100010001

I can not guarantee that I give you advice that will work, since I did it for a long time, But if you want to generate fake pages at the same level of nesting, you only need to change the path, adding + 1 to the last digit, and leaving the depth unchanged.

By example:

from yourapp.models import FakePage
k = 1
for i in range(5):
    k = k + 1
    page = FakePage(
    title = ('faketitle{}').format(k),
    path = ('{0:04}').format(k)
    depth = 3,
    )
    page.save()

But there is a better way:

from wagtail.wagtailcore.models import Page
from yourapp.models import FakePage

pages = Page.objects.all() # Get all pages

page = Page.objects.get(pk=3) # For example, take a page with pk = 3

fakepage = FakePage(title='fakepage title') # Create the desired page

page.add_child(instance=fakepage) # Add children page to the parrent page

In this case, you do not need to worry about the depth and the path.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda