Coder Social home page Coder Social logo

blemmy's Introduction

blemmy's People

Contributors

khashashin avatar loleg avatar movingwater avatar

Watchers

 avatar  avatar  avatar

blemmy's Issues

Adding additional data in the DRF api endpoint

Im trying to create restaurant menu table for 2 years. And to create a Database i created model class like:
cultina model class Week

stackoverflow question

YEARS = (
    (2017, 2017),
    # (2018, 2018),
)
WEEKS = (
    (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),
    (7,7),(8,8),(9,9),(10,10),(11,11),(12,12),
    (13,13),(14,14),(15,15),(16,16),(17,17),(18,18),
    (19,19),(20,20),(21,21),(22,22),(23,23),(24,24),
    (25,25),(26,26),(27,27),(28,28),(29,29),(30,30),
    (31,31),(32,32),(33,33),(34,34),(35,35),(36,36),
    (37,37),(38,38),(39,39),(40,40),(41,41),(42,42),
    (43,43),(44,44),(45,45),(46,46),(47,47),(48,48),
    (49,49),(50,50),(51,51),(52,52),(53,53),
)
DAYS = (
    ('Montag',1),
    ('Dienstag',2),
    ('Mittwoch',3),
    ('Donnerstag',4),
    ('Freitag',5),
)

class Week(models.Model):
    country = CountryField(
        verbose_name='Land', blank=True, null=True, blank_label='Wochenspezialität ist aus ...')
    year = models.IntegerField(verbose_name='Jahr', choices=YEARS,
        null=True)
    week = models.SmallIntegerField(verbose_name='Woche' ,choices=WEEKS,

and my endpoints.py have:

from wagtail.api.v2.endpoints import BaseAPIEndpoint

from .models import Week, Ingredient, Menu

class WeekAPIEndpoint(BaseAPIEndpoint):
    model = Week
def register_endpoints(api_router):
    api_router.register_endpoint('week', WeekAPIEndpoint)

And if I follow the link http://saad1.khashashin.com/api/v2/week i get this:

enter image description here

Can I somehow add data that will be equal "year" and "week" to this endpoint http://saad1.khashashin.com/api/v2/week like here:

{
    "meta": {
        "total_count": 2
    },
    "items": [
        {
            "id": 1,
            "year": 2017,
            "week": 22,
            "meta": {
                "type": "cultinadb.Week",
                "detail_url": "http://saad1.khashashin.com/api/v2/week/1/"
            }
        },
        {
            "id": 2,
            "year": 2017,
            "week": 21,
            "meta": {
                "type": "cultinadb.Week",
                "detail_url": "http://saad1.khashashin.com/api/v2/week/2/"
            }
        }
    ]
}

from here http://saad1.khashashin.com/api/v2/week/1:

enter image description here

Its hard to explane for me. I just need them to be available before I click on the link http://saad1.khashashin.com/api/v2/week/1.

Django Search Function inside ForeignKey

I have a class with huge amount of data and another class which should take the title value from this class.
How can I add a search function to ForeignKey as you can see in following Image. Or does Django have a way to solve this problem? Thanks!
I created a similar theme on stackoverflow

Search inside ForeignKey

class Menue(models.Model):
    title = models.CharField(max_length=255)
        panels = [
            FieldPanel('title', classname="col12"),
        ]
def __str__(self):
    return self.title

class Wochen(models.Model):
    menu_1 = models.ForeignKey(Menue,
        null=True, blank=True, on_delete=models.PROTECT, 
        related_name="menu_1+")
    panels = [
        FieldPanel('menu_1', classname="col12"),
    ]
def __str__(self):
    return self.menu_1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.