Giter Club home page Giter Club logo

Comments (5)

knoxvilledatabase avatar knoxvilledatabase commented on August 20, 2024 2

Right! There is no longer a need for Django REST, JustPy can communicate directly to the Django ORM on the backend without the need for AJAX/JSON/REST calls from the front end.

Just import your Django Project with:

sys.path.append('../path_to_project')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django import setup
setup()

Import your django models:
from my_django_project.models import MyModel

Now JustPy can communicate directly to the Django ORM without the need for Django REST. Here is a simple class that changes a Django model without REST:

import justpy as jp

class ChangeDjangoModelFromJustPy(jp.QDiv):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.django_model = kwargs.get('django_model', None)
        self.django_instance_id = kwargs.get('django_instance_id', None)
        self.django_field_to_change = kwargs.get('django_field_to_change', None)
        self.new_django_value_to_set = kwargs.get('new_django_value_to_set', None)
        jp.QBtn(text=kwargs['button_text'], click=self.change_django_model, a=self)

    def change_django_model(self, msg, target):
        kwargs={self.django_field_to_change: self.new_django_value_to_set}
        self.django_model.objects.filter(id=self.django_instance_id).update(**kwargs)

ChangeDjangoModelFromJustPy(
    django_model=MyModel,
    django_instance_id=1,
    django_field_to_change='enabled',
    new_django_value_to_set=False,
    button_text='Change Any Value on Any Field on Any Django Model with No REST API',
    a=wherever_you_want,
)

So elegant and powerful!

Credit for the JustPy Django integration goes to https://github.com/johnrtipton

from justpy.

elimintz avatar elimintz commented on August 20, 2024

Thanks for using JustPy and for catching this.

Not clear why this is not working. There is no evident problem in the code. It treats input_style and input_class just like any other prop. I'll look further into this.

If you create anything interesting with JustPy that can showcased, please let me know.

from justpy.

knoxvilledatabase avatar knoxvilledatabase commented on August 20, 2024

One of the most fantastic things I love about JustPy is importing the Django ORM to eliminate REST:
sys.path.append('../path_to_project')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django import setup
setup()
from my_django_project.models import MyModel
import justpy as jp
...

As for QSelect, when I add regular "style" argument with text decoration it adds the text decoration to topmost label but it appears that the nested 'q-field__native' color styling is overidding the QSelect style.

When I add an "input_style" argument I don't see the style anywhere.

Here is an example of QSelect with style argument:

jp.QSelect(style='color:#0088cc !important;text-decoration: underlinedotted',)

Style is located on label style=...

<div><label for="f_ea4f8949-f28e-452d-8183-f9253357f2b7" class="q-field row no-wrap items-start q-select q-field--auto-height q-select--without-input q-field--borderless q-field--float q-field--dense" style="color: rgb(0, 136, 204) !important; text-decoration: underline dotted;"><div class="q-field__inner relative-position col self-stretch column justify-center"><div tabindex="-1" class="q-field__control relative-position row no-wrap text-blue"><div class="q-field__control-container col relative-position row no-wrap q-anchor--skip"><div id="24" class="q-field__native row items-center"><span>Building A</span><input tabindex="-1" class="q-select__autocomplete-input no-outline"><div tabindex="0" id="f_ea4f8949-f28e-452d-8183-f9253357f2b7" class="no-outline"></div></div></div><div class="q-field__append q-field__marginal row no-wrap items-center q-anchor--skip"><i aria-hidden="true" role="presentation" class="q-select__dropdown-icon q-icon notranslate"></i></div><!----></div></div></label></div>

When using QSelect input_style I don't see the style anywhere:

jp.QSelect(input_style='color:#0088cc !important;text-decoration: underlinedotted',)

<div><label for="f_0809afcd-fd7d-416f-879f-ed68f0e3ae57" class="q-field row no-wrap items-start q-select q-field--auto-height q-select--without-input q-field--borderless q-field--float q-field--dense"><div class="q-field__inner relative-position col self-stretch column justify-center"><div tabindex="-1" class="q-field__control relative-position row no-wrap text-blue"><div class="q-field__control-container col relative-position row no-wrap q-anchor--skip"><div id="24" class="q-field__native row items-center"><span>Building A</span><input tabindex="-1" class="q-select__autocomplete-input no-outline"><div tabindex="0" id="f_0809afcd-fd7d-416f-879f-ed68f0e3ae57" class="no-outline"></div></div></div><div class="q-field__append q-field__marginal row no-wrap items-center q-anchor--skip"><i aria-hidden="true" role="presentation" class="q-select__dropdown-icon q-icon notranslate"></i></div><!----></div></div></label></div>

I also tried the color argument and that doesn't seem to have any effect either, it seems that "q-field__native overrides any font color styling.

As a workaround, I can add .q-field__native{color:inherit} to the webpage css to fix the color issue and instead of using input_style, just use the style argument on QSelect.

from justpy.

elimintz avatar elimintz commented on August 20, 2024

Thank you for the work around suggestion.

Could you please explain a little more why you combine Django features and JustPy? What do you mean by "eliminate REST"? Do you mean you don't need to build a Django backend to serve data using an API to the front-end?

from justpy.

elimintz avatar elimintz commented on August 20, 2024

Beautiful! Thanks,

from justpy.

Related Issues (20)

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.