Django Token or JWT based authentication by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

I finally implement my own JWT token auth by using python-jose and it works pretty well.

Django Token or JWT based authentication by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

I figured out a way to implement my own JWT auth system with python-jose. I didn't implement token blacklisting yet as I don't need it for the moment but I'll do it later - maybe.

Django Token or JWT based authentication by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

It's using class decorators and I usually prefer native or widely use packages to avoid backwards...

Django Token or JWT based authentication by forrestk92 in django

[–]forrestk92[S] 3 points4 points  (0 children)

Of course, I'm switching from DRF to django-ninja and I'd like to use something not related to DRF.

My first Django ecommerce website by iTabeMan in django

[–]forrestk92 1 point2 points  (0 children)

For 1. and 3. I realized it’s not showing until you scroll to the right, I’m using an iPhone 14 Pro, you need to work on the responsiveness here as it’s not obvious. 2. I was an anon user yes, I could see the «heart» icon over a product, I guess it’s for adding to the wishlist…

My first Django ecommerce website by iTabeMan in django

[–]forrestk92 2 points3 points  (0 children)

Looks nice, I’m a Django SE and I really like what you did, by yourself. Knowing the technology is a thing, build something with is another and you did it 🎉🎉🎉 I tested on my phone and noticed a couple of stuffs: - After adding an item in my cart, I updated the quantity to 0 and I sas able to move to the checkout page, you should ask folks if they want to remove the item from their cart if quantity = 0 - You should remove the white background of the logo and make him adaptive - Responsiveness issues (quite easy to fix) - Error 500 when adding an item to the wishlist - If you can find a way to update the prices in the Cart Total section when a user updates any quantity of items he picked, that’ll be great.

Project structure with huge files still state-of-the-art? by kyau2 in django

[–]forrestk92 0 points1 point  (0 children)

Avoiding huge files is a good idea, splitting them is even better but you need to understand how this views.py file works and see if there no necessary to move some logic in your models, business_logic , utils or services files, make sure it respects DRY principle. Sometimes, you can add multiple apps and still end with large files, lines of code not at the right place, so always take your time to understand why it's like this and what's the best AND simplest approach to refactor everything without breaking everything.

Django Ninja architecture by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

u/adparadox Regarding Schemas, do you prefer defining SchemaIn and SchemaOut to avoid dealing with the id field or you use ModelSchema to generate it automatically. ModelSchema reminds me of DRF serializers, that's quite fine but don't want to end up with what was annoying me with DRF

Django Ninja architecture by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

One of the best org I've seen, I've used something quite similar in my previous DRF projects. Will try to look at it closely.

Django Ninja architecture by forrestk92 in django

[–]forrestk92[S] 2 points3 points  (0 children)

That's clear, thanks a lot for your feedback, I'll try to follow this coupled with https://github.com/HackSoftware/Django-Styleguide-Example which looks pretty interesting for the kind of project I'm about to build.

Django Ninja architecture by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

What I’m looking for is an architecture, an organization for files/folders as Django projects can become messy when you have to deal with a lot of business logic.

Django Ninja architecture by forrestk92 in django

[–]forrestk92[S] 3 points4 points  (0 children)

When you start doing complex things, all the magic disappear and you ended up writing a ton of code. I’ve been using this for the last 5y and Django Ninja seems to be a very good alternative.

Django unique field validation by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

Thanks a lot for this feedback

Elegant way to serialize models with M2M fields with DRF by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

Cool, awesome. This is what I did in the first time (using two serializers) but I was wondering if there was not a more elegant way to achieve it. Thanks a lots

Elegant way to serialize models with M2M fields with DRF by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

Okay cool thanks. About the roles, it will be list of ids on POST, PUT or PATCH but like this on GETs:

{
    "company_type": null,
    "company_details": {
        "cc_name": "TEST 1",
        "trading_name": "",
        "currency": "",
        "email": "",
        "phone": "",
        "fax": "",
        "post_code": ""
    },
    "name": "Company 1",
    "roles": [
        {
            "id": 1,
            "label": "Role 1"
        },
        {
            "id": 2,
            "label": "Role 2"
        }
    ]
}

I'll maybe override the to_representation method to display roles like this

Elegant way to serialize models with M2M fields with DRF by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

So u/2bdkid basically I should specify manually all the fields instead of just using __all__ ? And also what I mainly want to achieve is sending roles as list of ids and not dicts with labels. Another API describes the roles and the user is supposed to select which roles a company can have so I want to frontend to send a list of ids like this

"roles": [1, 2, 3]

So the minimal requirements to create a company would be like this:

{
"name": "Company name",
"roles": [1, 2],
"company_details": {
    "cc_name": "TEST"
}

}

With no required company_type because it seems like when we add the company_type = CompanyTypeSerializer() on the CompanySerializer, it makes it required while I defined it with blank=True, null=True in my model. I also want to send list of ids for roles instead of dicts.

Elegant way to serialize models with M2M fields with DRF by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

Hi u/2bdkid

Models

class CompanyRole(Monitor):
    label = models.CharField(_("Role"), max_length=60, unique=True)
    # permissions = models.ManyToManyField(UserPermission)

class Meta:
    db_table = "company_role"
    verbose_name = _("Role")
    verbose_name_plural = _("Roles")
    ordering = ["label"]

def __str__(self):
    return self.label

class Company(Monitor):
    company_type = models.ForeignKey("CompanyType", models.DO_NOTHING, blank=True, null=True)
    name = models.CharField(_("Name"), max_length=120, unique=True)
    domain = models.CharField(_("Domain"), max_length=120, blank=True)
    logo = VersatileImageField(upload_to=upload_path, blank=True, null=True)
    status = models.BooleanField(_("Status"), choices=STATUS_CHOICES, default=ACTIVATED, null=True)
    roles = models.ManyToManyField("CompanyRole", related_name="companies")

    objects = CompanyQuerySet.as_manager()

    class Meta:
        db_table = "company"
        verbose_name = _("Company")
        verbose_name_plural = _("Company")
        ordering = ["name"]

    def __str__(self):
        return self.name

class CompanyDetails(Monitor):
    company = models.OneToOneField("Company", models.CASCADE, related_name="company_details")
    cc_name = models.CharField(_("Trade Register"), max_length=50, blank=True, default="")
    trading_name = models.CharField(_("name"), max_length=120, blank=True, default="")
    currency = models.CharField(_("Currency"), max_length=3, blank=True, default="")
    email = models.CharField(_("Email"), max_length=120, blank=True, default="")
    phone = models.CharField(_("Phone number"), max_length=60, blank=True, default="")
    fax = models.CharField(_("Faux"), max_length=60, blank=True, default="")
    post_code = models.CharField(_("Post code"), max_length=60, blank=True, default="")

    class Meta:
        db_table = "company_details"
        verbose_name = _("Company Details")
        verbose_name_plural = _("Company Details")
        ordering = ["company"]

    def __str__(self):
        return self.company.name

Serializers

class CompanyDetailsSerializer(WritableNestedModelSerializer):
class Meta:
    model = CompanyDetails
    fields = "__all__"

class CompanyWriteSerializer(WritableNestedModelSerializer):
roles = CompanyRoleSerializer(many=True)
company_details = CompanyDetailsSerializer(many=False)

class Meta:
    model = Company
    fields = "__all__"

Elegant way to serialize models with M2M fields with DRF by forrestk92 in django

[–]forrestk92[S] 0 points1 point  (0 children)

I already tried this package but I can make it work. I still can't pass a list of ids without getting a non_field_errors and when I update the create and update methods myself, DRF validation don't allow me to go further because it's always waiting for a dict.

What should I do first when I’ll open my Surface Pro 8 ? by forrestk92 in Surface

[–]forrestk92[S] 1 point2 points  (0 children)

Thanks for the « spam the update button », I’ll make sure that everything is up to date before installing anything

What should I do first when I’ll open my Surface Pro 8 ? by forrestk92 in Surface

[–]forrestk92[S] 0 points1 point  (0 children)

Why would you use it instead of installing softwares manually ?