Angular forms for django rest framework
Project description
This repo provides Django mixins and Angular library for rapid development of create/edit dialogs for django rest framework. It depends on Angular5 and Material UI.
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 <inpage-django-form> tag.
<inpage-django-form django_url="/api/1.0/cities/"
(submit)="submit($event)"
(cancel)="cancel($event)"></inpage-django-form>
Demo and sample source files
See demos at http://mesemus.no-ip.org:12569
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,
DjangoFormModule,
HttpClientModule,
...
],
providers: [
{
provide: ErrorService,
useClass: MatErrorService
},
],
bootstrap: [AppComponent]
})
export class AppModule {
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-angular-dynamic-forms-0.5.22.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab59ddb4a08f2bb8a9e848d2917dfea4b1974cc16708896b77bf6651f93eba94 |
|
MD5 | 743a82fa4a06b32154b3b148e9b93fea |
|
BLAKE2b-256 | f0717711b93883164b214ef9dd41575f71f22de14a890cfa224771622cf79c33 |