Categories
Mastering Development

Automatically assigning User token to custom profile model django rest framework

I currently have a signal that automatically creates a Token object for a User when they sign up to the website. I also have a custom User model, UserProfileInfo, in which I have a field that connects a Token to the User token = models.OneToOneField(Token,related_name=’token’,on_delete=models.CASCADE,blank=True,null=True) However, I want this to be automatically assigned when the […]

Categories
Mastering Development

Django DRF : how change to change Date format in my serializer.py?

I am new to Django DRF and I need a small tip. My Problem : I want to change the standart models.DateField to the following format “%d-%m-%Y”. I want to do it for the field “birthday” or in general for the project. I tried in directlty in the model.py with : …. birthday = models.DateField(null=True […]

Categories
Mastering Development

C#: Instantiating class with non-null members? [closed]

I have a class auto-generated from an XSD file, which I need to instantiate, then assign some values and serialize it. The object graph for this class is quite large, and the non-primitive inner classes it references are not initialized, although some of those classes define default values for fields/properties; I would like to keep […]

Categories
CMS Development Wordpress

I want to add the alt attribute to all the photos!

Hello everyone and I found you well, I have a problem with a dynamic site that contains over 200,000 photos, it is a news site. The site is built on the WordPress platform and has many changes to suit our business. In vain I complete the attribute alt for each photo he does not appear […]

Categories
Mastering Development

Brightway2 Excel Database Import Problem .write_database() ecoinvent

First of all, I am pretty new to bw2 and LCAs in general, so please be understanding. I currently work on a tool which exports the exchanges of an ecoinvent activity to an excel-sheet. Within the excel-sheet, I would like to change amounts and add new or delete exchanges. After that, my plan was to […]

Categories
Development

Multiple Django OneToOne ModelForm Validation in single Create View

I have three modelforms and I am trying to validate those forms in a single view. All forms are connected with OneToOne relation. I cannot validate subforms after main form ins same view. Tried few solutions and I guess I am doing something wrong and if someone can help I can redo it few times […]

Categories
Development

UNIQUE constraint failed: new__users_profile.user_id. Python Django

django.db.utils.IntegrityError UNIQUE constraint failed sqlite3.IntegrityError: UNIQUE constraint failed: new__users_profile.user_id The above exception was the direct cause of the following exception: new__users_profile.user_id Error occurs when I’m trying to register new user, login to an existing user and when I am trying to migrate. I’ve tried to delete all migrations and migrate once again but it didn’t […]

Categories
Development

M2M relations not deleted after clear()

If a user is de-activated I want all memberships deleted. I thought this code in models.py would do it. But is doesn’t, the relation is still there. class User(AbstractUser): membership_type = ManyToManyField(MembershipType, blank=True) …. def __init__(self, *args, **kwargs): super(User, self).__init__(*args, **kwargs) self.old_is_active = self.is_active def save(self, **kwargs): # Membership is cancelled if self.old_is_active is True […]

Categories
Development

How do I modify my Django REST endpoint to automatically create a dependent model when creating the submitted model?

I’m using the djangorestframework module to set up an API to update/read my models. I have these models … from django.db import models from address.models import AddressField from phonenumber_field.modelfields import PhoneNumberField from address.models import State from address.models import Country class CoopTypeManager(models.Manager): def get_by_natural_key(self, name): return self.get_or_create(name=name)[0] class CoopType(models.Model): name = models.CharField(max_length=200, null=False) objects = CoopTypeManager() […]

Categories
CMS Development Wordpress

How to customize archive widget only for cpt?

I have one custom post type named as ‘portfolio’, I want to customize and display archives (only cpt archives) on sidebar ‘archive-portfolio.php’. How to customize this <?php wp_get_archives( apply_filters( ‘widget_archives_args’, array( ‘type’ => ‘monthly’, ‘show_post_count’ => $count, ), $instance ) ); ?>