Giter Site home page Giter Site logo

denisroldan / django-angular-dynamic-forms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oesah/django-angular-dynamic-forms

0.0 2.0 0.0 622 KB

Angular 6 reactive forms integrated with Django Rest Framework viewsets, rapid development of forms

License: MIT License

Python 16.85% Shell 0.66% JavaScript 1.31% TypeScript 79.11% HTML 1.59% CSS 0.49%

django-angular-dynamic-forms's Introduction

Django Rest Framework meets Angular 6 dynamic forms

This repo provides Django mixins and Angular library for rapid development of create/edit dialogs for django rest framework. It depends on Django 2, Angular 6 and Material UI.

Note: support for Angular 5 and Django<2 is not actively developed - use release/angular5 branch or 1.1.* versions of packages if you need that.

On django side, extend your Viewset to use AngularFormMixin and optionally configure the mixin by providing either layout information or field defaults (such as css classes). See demos for details.

class CityViewSet(AngularFormMixin, viewsets.ModelViewSet):
    """
    API for cities
    """
    queryset = City.objects.all()
    serializer_class = CitySerializer

On angular side, use DjangoFormDialogService to display a dialog:

constructor(private dialog: DjangoFormDialogService) {
}
createCity() {
    this.dialog.open('/api/1.0/cities/').subscribe(result => {
        console.log('City created, result from server is:', result);
    });
}

You can also display the form inside your own component via <django-inpage-form> tag.

<django-inpage-form django_url="/api/1.0/cities/"
                    (submit)="submit($event)"
                    (cancel)="cancel($event)"></django-inpage-form>

Demo and sample source files

See demos at http://mesemus.no-ip.org:12569

image

With a bit of work on your side, foreign keys and many-to-many relationships are supported as well (see the demos for details)

image

Installation

Django side:

pip install django-angular-dynamic-forms

Angular side:

npm install --save django-angular-dynamic-forms @ng-dynamic-forms/core @ng-dynamic-forms/ui-material

To render forms, this library uses https://github.com/udos86/ng-dynamic-forms - do not forget to add it to your package.json.

and add DjangoFormModule to imports. You will need to provide your own ErrorService for showing communication errors back to the user. See the demo/angular/src/app/mat-error.service.ts for an example implementation.

import {DjangoFormModule, ErrorService} from 'django-angular-dynamic-forms';

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        BrowserAnimationsModule,
        DynamicFormsCoreModule.forRoot(),
        DynamicFormsMaterialUIModule,
        DjangoFormModule,
        HttpClientModule,
        ...
    ],
    providers: [
        {
            provide: ErrorService,
            useClass: MatErrorService
        },
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

Configuration

If your angular and django server are on the same host/port (see https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md for development tips), no configuration is necessary.

If angular and django are on different hosts/ports, set django setting ANGULAR_FORM_ABSOLUTE_URLS=True ( thanks @sssolid for pointing this out).

django-angular-dynamic-forms's People

Contributors

angular-cli avatar denisroldan avatar mesemus avatar nsmolenskii avatar

Watchers

 avatar  avatar

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.