4

I recently forked Saleor 2.9 for a web app I am building for an art gallery that wants to display their products for sale as well as give their artists some publicity. I want to be able to have a bunch of cards (like "our team" components) that pull data from an Artists table on the back-end that stores information about the artists' names, emails, origins, etc, and then display it on the front-end. I am struggling to see how to modify the models/DB to create a new "Artists" table with name, email, info, and then to create a manyToMany-like relationship with the products I've populated in the DC, giving the products a "created by" attribute. There are tons of models files throughout the /dashboard directory, and even when I make changes to the core models to create an artist class, I don't know how to get it to show on the dashboard so artists can be created/modified from there.

I would like to make it so that the client (non-technical) can add artists and have them show up on the artists page I will make, somewhat like products show up on their pages (but obviously I cannot create a new category "Artist" as artists cannot have prices or shipping as they are people; and there are other attributes I would want like email that a product cannot have, either. They are also different to staff on the website, so I cannot use the "staff management" functionality.)

I looked at this question but Saleor structure has changed since then, and that was a relatively minor attributal change to an existing class (User) as opposed to the creation and integration of a new class. I'm surprised that despite extensively searching for anything on how to do something as straightforward as create a new model there is little documentation and discussion online; I must be missing something.

Please help :) Thank you!

Tanishq Kumar
  • 263
  • 1
  • 13
  • I am probably too late but saleor is just a regular django application which mean you can add a django model with the business logic and data you want refere to the very extensive django documentation for doing that – grll Apr 28 '20 at 19:00
  • @grll Thank you! Believe it or not I am still working on the same thing, except now writing graphQL mutations for those model changes (which I'm also stuck on ;). It's my first time making changes to a huge code-base: any tips on how to know what does what and what to change given it's a huge code-base without much documentation for devs? – Tanishq Kumar Apr 29 '20 at 07:44
  • graphQL is amazing for quickly performing the operation you need. If you are not familiar with it I would recommand you to first read https://graphql.org/learn/ (at least queries and mutations) then just hit the playground available at `http://localhost:8000/graphql/` when you launch saleor and start querying. In the playground you have a docs / schema tab very useful for looking at what queries / mutations are available and with what parameters. – grll Apr 29 '20 at 08:32
  • @grll Thanks--I've already done both those things. My confusion was more around how to undersand how Saleor goes about creating queries and mutations as opposed to using them, since I'll have to create some queries/mutations to manage my new models from the UI. – Tanishq Kumar Apr 29 '20 at 08:35
  • 1
    Ah sorry then you will need to check the source code start with a simple model like `saleor/graphql/discount/` for example there you will see how to define mutations, resolvers etc.. Saleor uses the python graphene package to make the graphQL server – grll Apr 29 '20 at 08:41

1 Answers1

-1

The django way to create new models, (and Saleor´s backend is django based) is:

  1. You should create a new app on your store backend (the django part of saleor) with:

    $ python manage.py startapp artist

  2. Create your Artist model, with all the fields you want such as email, etc... in the file: artist/models.py.
  3. Modify the Product model in the file product/models.py by importing the Artist models and adding a ForeignKey (for example) relationship to it.
  4. Register the new artist app in your settings.py's "INSTALLED_APPS".
  5. Run python manage.py makemigrations... (Check they include your changes to models)
  6. Run python manage.py migrate.

That should be it. 'less I`m forgeting something, in which case, please post back when you have moved forward with this.


Notes:

  • You may want to back up your DB first.
  • Also when applying these migrations, django will ask you for a placeholder value for products which where in your DB before Product had an Artist field.

References:

Aerials
  • 4,231
  • 1
  • 16
  • 20
  • 1
    Creating new models in django would not just automatically surface those models to Saleor so not sure how this is helpful – AlxVallejo Aug 22 '21 at 15:44