Tuesday, 14 June 2022

scss, css import styling file.scss css file starts with _


Suppose your folder structure is like this


if you run the command

sass --watch scss:css

only style.css and style.css.map files will be created, sass compiler will omit _list.scss without converting its content into a CSS file.


the only way that you can use partials is to import them into another .scss file with

@import 'list.scss';

if you remove the '_' in front of _list.scss the outcome of the command will be


The main purpose of using partials is to break down our CSS code into several pieces which are easier to maintain. Hope this helps. Thanks.

in .json file

still need _list.scss for fullPath

Angular Ag Grid modular based import

 Enterprise version 

(To use row grouping etc)


    "dependencies": {

        "@ag-grid-community/angular": "23.2.1",

        "@ag-grid-enterprise/all-modules": "23.2.1",

        "@ag-grid-community/client-side-row-model": "23.2.1",}


import { enableProdMode } from '@angular/core';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

import { environment } from './environments/environment';

import { LicenseManager } from '@ag-grid-enterprise/core';

if (environment.production) {



if (environment.agGridLicenseKey) {




    .catch(err => console.error(err));


import { AgGridModule } from '@ag-grid-community/angular';

import { AllModules, ModuleRegistry } from "@ag-grid-enterprise/all-modules";



import {












} from '@ag-grid-enterprise/all-modules';

import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';








Community Version

Your Component.html:





import { ColDef, GridApi, GridOptions, GridReadyEvent, RowNode, GridSizeChangedEvent, Module } from '@ag-grid-enterprise/all-modules';

import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';

    public modules: Module[] = [ClientSideRowModelModule];

Tuesday, 7 June 2022

Friday, 3 June 2022

GIT ammend commit msg && revert commit (not pushed)

ammend last commit msg :

git commit --amend



$ git reflog
(HEAD -> master)
d846aa8 HEAD@{0}: commit: 5th git commit: 5 files
0c59891 HEAD@{1}: commit: 4th git commit: 4 files
4945db2 HEAD@{2}: commit: 3rd git commit: 3 files
defc4eb HEAD@{3}: commit: 2nd git commit: 2 files
2938ee3 HEAD@{4}: commit: 1st git commit: 1 file
$ git revert 4945db2

Wednesday, 25 May 2022

Django alter existing migration including add not null column


To elaborate on my comment above...

Adding a new non-nullable ForeignKey in Django is generally a three-step process.

  1. First, you add the new ForeignKey to your model definition with null=True, and run makemigrations. This will create a migration that will add the field, nothing special about it. Executing this migration will add a column with all rows having NULL as the value.
  2. Second, you create a new empty migration for the same app (makemigrations --empty), then edit that migration to contain a data migration step. This is where you'll need to, according to your business logic, choose some value for the new foreign key.
  3. Third, you modify the ForeignKey in your model definition to set null=False and create a third migration with makemigrations. Django will ask whether you've dealt with nulls somehow – you need to say that "yep, I swear I have" (since you did, above in step 2).

In practice, for a simplified version of OP's question where we'll want to add an User foreign key:

Original state

class Post(models.Model):
    name = models.CharField(max_length=100)

1a. Add nullable field.

class Post(models.Model):
    name = models.CharField(max_length=100)
    author = models.ForeignKey(User, null=True, on_delete=models.CASCADE))

1b. Run makemigrations.

$ python manage.py makemigrations
Migrations for 'something':
    - Add field author to post

2a. Create a new empty migration.

$ python manage.py makemigrations something --empty -n assign_author
Migrations for 'something':

2b. Edit the migration file.

More information on data migrations can be found, as always, in the manual.

from django.db import migrations

def assign_author(apps, schema_editor):
    User = apps.get_model('auth', 'User')  # or whatever is your User model
    Post = apps.get_model('something', 'Post')  # or wherever your Post model is
    user = User.objects.filter(is_superuser=True).first()  # Choose some user...
    assert user  # ... and ensure it exists...
    Post.objects.all().update(author=user)  # and bulk update all posts.

class Migration(migrations.Migration):

    dependencies = [...]

    operations = [
        migrations.RunPython(assign_author, migrations.RunPython.noop),

3a. Make the field non-nullable.

class Post(models.Model):
    name = models.CharField(max_length=100)
    author = models.ForeignKey(User, null=False, on_delete=models.CASCADE))

3b. Run Makemigrations.

Answer truthfully to the question – you've just added a RunPython operation.

$ python manage.py makemigrations something -n post_author_non_null
You are trying to change the nullable field 'author' on something. to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Ignore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)
 3) Quit, and let me add a default in models.py
Select an option: 2
Migrations for 'something':
    - Alter field author on post

All done!

Running migrate will now run these three migrations and your model will have author without data loss.

Django rever migrations


python manage.py showmigrations

python manage.py migrate {app name from show migrations} {00##_migration file.py}

If you want to revert all migrations, use zero as the name of the migration:

python manage.py migrate app_name_here zero

Delete the migration file. Once the desired migration is in your models...

python manage.py makemigrations
python manage.py migrate

Django migrations seed


Simple 1 : 

manually create a json file via build in django cmd, then use 

python manage.py loaddata <file>

simple file can be created using 

For example, we want to create two Admin object and make the fixture file. So make it a regular model for admin, then we could run dumpdata command. First, create the object of the model (we’ll use Django shell, just choose which one is most comfortable). (Admin model in admin_birpen app)

python3 manage.py shell
>>> from admin_birpen.models import Admin
>>> Admin(pk=1, username="@adminPPL").save()
>>> Admin(pk=2, username="@adminPacil").save()

Then we can dump the created data in JSON file a.k.a. the fixture file in seed/0008_Admin.json with 4 indentation space.

<admin_birpen> is the app name

python3 manage.py dumpdata admin_birpen --indent 4 > seed/0008_Admin.json

Or generate complex json file using

django-seed plugin

pip install django-seed

For installation, just run pip install django-seed. More documentation about django-seed visit this link. So I will simulate generate the fixture for the model Pengumuman. Long short story, Pengumuman model has more than 13 fields with quite a lot of model dependencies.

So how do we generate the fixture? Simple, just run python3 manage.py seed pengumuman --number=2, so from this command, we will generate 2 object models in the pengumuman application. This command is not to generate fixture directly, but rather to make the object directly inputted to the database. So how do we generate the fixture? As previously explained, we can use dumpdata command!