0

I'm learning Django and I have a problem because I don't know how to put my intention a model.

On my public page I would like to be able to dynamically change the content of my homepage. However, I don't want to create a PageModel - I want only a HomeConfig model with which I can define different texts, images, etc. My problem is that this model could only have one entry but a model isn't made for just one entry.

@Edit: Here is an example to perhaps illustrate the problem a little better. I would like to have the possibility to change the logo, the texts, the buttons, the images... change. But since the design is more complicated than in the example, it doesn't work to create a simple pagemodel with a text editor field. Here is the example

masdot
  • 43
  • 7
  • 1
    Are you trying to make a landing page for something like A/B testing? Let's say image A and image B. What determines which image to display? Do you have any starter code? – Jarad Jun 03 '21 at 20:51
  • Not quite. I would like to have the possibility to change the text of the homepage for my project via the Django admin interface. However, since the homepage is a bit more complicated, it does not work to simply insert a text field via a page model. @Jarad – masdot Jun 04 '21 at 13:18
  • I added an more detailled description @Jarad – masdot Jun 04 '21 at 13:30
  • 1
    A model CAN have only one record (instance), if you wanted it to. You would just edit the existing record. Your view would send the instance to the template, and you render it how you want. – Jarad Jun 04 '21 at 16:48
  • Can I then forbid the creation of multiple records? Or should I simply not create any more? – masdot Jun 05 '21 at 10:04
  • Just don't create another one, or [disable add action](https://stackoverflow.com/questions/4143886/django-admin-disable-the-add-action-for-a-specific-model) if just using admin, or do a check for if the ID does not equal the ID you define, don't allow. There's a lot of ways. These are just ideas. I've never tried this so I may not be the most informed on this. – Jarad Jun 05 '21 at 18:49
  • Thanks to you! The solution was closer than I thought xD – masdot Jun 05 '21 at 18:51

0 Answers0